RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"it doesnt clone gui please help and fix"
Sure, I can help with that. Here's a corrected version of your script. ```lua local function onPartTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local gui = script:FindFirstChild("M4") if gui then local clonedGui = gui:Clone() clonedGui.Parent = player:WaitForChild("PlayerGui") local function onPartTouchEnded() if clonedGui then clonedGui:Destroy() end end hit.TouchEnded:Connect(onPartTouchEnded) end end end script.Parent.Touched:Connect(onPartTouched) ``` In the original script, the problem was that the script was trying to access the PlayerGui directly from the player, which may not always be available immediately. The updated script uses the `WaitForChild` function to ensure the PlayerGui is available before trying to access it. Also, the `script.Parent.Parent` was changed to `script.Parent` as it seems like the script is supposed to be a child of the part that is being touched. If the script is not a direct child of the part, you would need to adjust this to point to the correct part.