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

Part.Touched to open GUI script locally won't work, what's wrong with it?

I have a local script in StarterGUI which when the part named 'ShopPart' is touched it makes a frame inside a screenGUI named 'Shop' visible. However for some reason this script does not work. I also want to make sure that only the player who touched the part can see the gui being opened (client side). I've tried testing this in studio and main game however the GUI won't oepn.

game.Workspace.ShopPart.Touched:Connect(function(hit)
	if hit then
	script.Parent.Shop.Frame.Visible = true
end

2 answers

✓ Accepted answer

You are finding if hit then What are you doing here? You should check if whatever touched the part (hit) is actually a player or not and then it if its, you would fire a RemoteEvent to the Client and so on and so forth.

Insert a RemoteEvent in ReplicatedStorage.

game.Workspace.ShopPart.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent)  then
 game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
        end
end)

Now, insert a local script inside the Frame.

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
        script.Parent.Frame.Visible = not script.Parent.Frame.Visible
end)

The best way to do it is have the touched script inside of a part with a server script.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = hit.Parent.Name
		print(player)
		game.Players[player].PlayerGui.Shop.Frame.Visible = true
	end
end)

This goes from whatever touches the part, and goes to the name of the character. It then takes the name of the character, and uses to find them in the Players.

5 comments

0

You can't change PlayerGUI from a server script you dumb idiot.

0

Actually, you can. I tested this script and it worked fine. It showed up only on my client.

0

@SilentsReplacement Maybe you should actually try something out before you flat out say it doesn't work ;)

0

It doesn't, his script is different. don't let your ego out.

0

@SilentsReplacement hold up buddy. You realize that my way is shorter than what you did AND it functions exactly how he wants it. If we are gonna talk about an ego check, that's you who needs one, my friend

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