Why won't this script work?

So I have a local script inside of a ScreenGui. It works, but it opens the gui for everyone in the server. Is there a way to fix it? I’m not much of a sciprter.

Local Script:

game.Workspace.EarthWorld.TrailShop.ShopPart.Touched:Connect(function()
	script.Parent.ShopFrame.Visible = true
end)

Check remotes in server side that enables that GUI too, with that script its impossible to open other clients GUIs

Sorry, I know this question may make me seem dumb. But where is the remotes in server side?

This should be a localscript, because the Touched event fires on the server (i think)

so if script.Parent.ShopFrame is in StarterGui it should work with a server script like this

workspace.EarthWorld.TrailShop.ShopPart.Touched:Connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        local PlayerGui = game.Players[hit.Parent.Name].PlayerGui
        local Frame = PlayerGui. YourWayToTheFrame --Change to the target (.screengui.frame maybe?)
        Frame.Visible = true
    end
end)

Try this maybe it will work

It works only once. And when you try going on the part again, it wont open

Do you have the TouchEnded event too? (when u stop touching it it closes the frame)

Nope. I only have a close button inside the frame. Should I add a TouchEnded event?

and that makes it Visible = false right?

Yes, it does make it Visible = false.

any errors?
ignore this → hfsdaczgnasrngxeuaisd

There is no error in the output.

Let me try making a separate script for the close button.

Ok if it works then solution it, if it doesnt text here

It doesn’t work. I think I might have read your reply with the script wrongly. It is supposed to be a script inside of ServerScriptService?

It can be inside the workspace or the part thats touched

The reason why your code isn’t working is because you aren’t checking if the LocalPlayer is touching the part. This can be fixed by checking if the hit part is a player and then check if that player is the LocalPlayer.

Fixed code:

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

game.Workspace.EarthWorld.TrailShop.ShopPart.Touched:Connect(function(hitPart)
	if Players:GetPlayerFromCharacter(hitPart.Parent) == LocalPlayer then
		script.Parent.ShopFrame.Visible = true
	end
end)

Its kinda complicated if you dont know whats going on in your game’s scripts.
Usually remotes are in ReplicatedStorage, but the important thing would be check the remotes that could be FireAllClients() referencing that GUI… Read the game scripts and understand them.

Thats true, but make no sense on the topic. A touched even in a server script, yeah it will fire in server side, a touched event in client side, will fire in client side, thats all.

If other clients are getting their client gui affected, its because a remore calling client scripts, to perform a change on the GUI

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.