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

Local and regular script clashing?

I have a game I'm developing, and I'm making a shop in it for armor and swords. When you enter a region specified by a blue circle, it SHOULD open a gui. It works once, and then doesn't run. It says it's done with the code, but nothing's appearing.

I think it might have something to do with the X script. I'll post it as well.

script.Parent.Touched:Connect(function(hit)
	print("Hitted")
	if hit.Parent:FindFirstChildWhichIsA("Humanoid")then
		print("Human")
		local Char = hit.Parent
		local function FindChar()
			for _,i in pairs(game.Players:GetChildren())do
				if i:IsA("Player")then
					if i.Character == Char then
						i.PlayerGui.ShopGui.Shop.Visible = true
						print("ED")
					end
				end
			end
		end
		FindChar()
	end
end)

Now the X:

script.Parent.MouseButton1Click:Connect(function(clk)
	script.Parent.Parent.Visible = false
end)

(The X's script is Local)

7 comments

0

please use :FindFirstChildWhichIsA, it is supposedly better than :FindFirstChildOfClass, by the way it wasnt supposed to change anything it was a suggestion, i was reading the code

0

Didn't work

0

wait so, the first code posted is in a server script?

0

yes

0

there is a problem here

0

you cant access playerguis through server scripts you need to use remote events

0

let me fix the scripts for you and it should work, hold on a minute

1 answer

✓ Accepted answer

Playerguis can only be accessed using client side scripts, so to do this, we use a remote event, so the server script looks like this:

add a remote event to game.ReplicatedStorage and name it whatever oyu want, ill use the name remote event for this script to not confuse you

script.Parent.Touched:Connect(function(hit)
    print("Hitted")
    if hit.Parent:FindFirstChildWhichIsA("Humanoid")then
        print("Human")
        local Char = hit.Parent
        local function FindChar()
            for _,i in pairs(game.Players:GetChildren())do
                if i:IsA("Player")then
                    if i.Character == Char then
                        game.ReplicatedStorage.RemoteEvent:FireClient(i)--this fires the remote event to that player whos gui you wanna mess with
                        print("ED")
                    end
                end
            end
        end
        FindChar()
    end
end)

then in local script:

script.Parent.MouseButton1Click:Connect(function(clk)
    script.Parent.Parent.Visible = false
end)


game.ReplicatedStorage.RemoveEvent.OnClientEvent:Connect(function()--this triggers when the remote event fires

	game.Players.LocalPlayer.PlayerGui.ShopGui.Shop.Visible = true

end)

3 comments

0

i dont know why clicking gets rid of the gui, but you can mess with that urself :) hope this helps

0

IT WORKED!!!! YESSSS!

0

glad i could help :3

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