Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This gui isn't moving when you touch a part?

So I want a GUI to move when a player touches a certain part. But I can't figure out the script.

wait(1)
function onTouched(hit)
hit.Parent.PlayerGui.BlackScreen:TweenPosition(UDim2.new(0, 0,1, 0),"Out" ,1)
end
script.Parent.Touched:connect(onTouched)

Can someone help?

1 answer

✓ Accepted answer

Your script is correct and 1 thing is certain. Touched events do work on local scripts unless they are placed in the Workspace and etc. You need to fire a RemoteEvent to the client and then make changes. Also keep your functions local and it seems like you are using a deprecated latter.

Please note that :connect is deprecated and use :Connect instead.

Insert a Remote Event in ReplicatedStorage.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

wait(1)

local function onTouched(hit)

if game.Players:GetPlayerFromCharacter(hit.Parent) then -- Gets the player from the character
        RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
       end
end
script.Parent.Touched:Connect(onTouched)

Now, insert a local script to BlackScreen.

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
        script.Parent:TweenPosition(UDim2.new(0, 0,1, 0),"Out" ,1)
end)

8 comments

0

False. Touched events do work in local scripts. It's the fact that he has his local script inside workspace. Local scripts don't work in workspace. If he put his local script in StarterGui then it would work.

0

well it worked for me

0

Yeah the scripts he provided works, just wanted to clarify that touched events do work in local scripts. It's just that you had your local script inside workspace.

0

Well, it was obvious, wasn't it? The part his touching is in the workspace, and the script is obviously inside the part, as his doing 'script.Parent.Touched'. I noticed it straight away at least lol.

0

But again, he didn't say if it were a local script or not. So fair enough, anyway like I said, just wanted to clarify that touched events indeed do work in local scripts.

0

That's not my point, I know they work on local scripts. I've another point.

0

Yeah but, in your answer you said that they 'DON'T' work in local scripts, until i said something that's when you added they they do work in StarterGui.. Again, I just wanted to comment to clarify that they do indeed work in local scripts, because your answer before saying that they don't work in local scripts could confuse some people.

0

Yeah, I agree on you. I'm sometimes a idiot at posting really quick explanations but in the end, find them a little wrong lol

This discussion is preserved as it was. New answers, comments, and votes are closed.