Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Local and regular script clashing?

Asked by 3 years ago
Edited 3 years ago

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)

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 AlexanderYar 788 — 3y
0
Didn't work TheB4dComputer 100 — 3y
0
wait so, the first code posted is in a server script? AlexanderYar 788 — 3y
0
yes TheB4dComputer 100 — 3y
View all comments (3 more)
0
there is a problem here AlexanderYar 788 — 3y
0
you cant access playerguis through server scripts you need to use remote events AlexanderYar 788 — 3y
0
let me fix the scripts for you and it should work, hold on a minute AlexanderYar 788 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
i dont know why clicking gets rid of the gui, but you can mess with that urself :) hope this helps AlexanderYar 788 — 3y
0
IT WORKED!!!! YESSSS! TheB4dComputer 100 — 3y
0
glad i could help :3 AlexanderYar 788 — 3y
Ad

Answer this question