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 4 years ago
Edited 4 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.

01script.Parent.Touched:Connect(function(hit)
02    print("Hitted")
03    if hit.Parent:FindFirstChildWhichIsA("Humanoid")then
04        print("Human")
05        local Char = hit.Parent
06        local function FindChar()
07            for _,i in pairs(game.Players:GetChildren())do
08                if i:IsA("Player")then
09                    if i.Character == Char then
10                        i.PlayerGui.ShopGui.Shop.Visible = true
11                        print("ED")
12                    end
13                end
14            end
15        end
16        FindChar()
17    end
18end)

Now the X:

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

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

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 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

01script.Parent.Touched:Connect(function(hit)
02    print("Hitted")
03    if hit.Parent:FindFirstChildWhichIsA("Humanoid")then
04        print("Human")
05        local Char = hit.Parent
06        local function FindChar()
07            for _,i in pairs(game.Players:GetChildren())do
08                if i:IsA("Player")then
09                    if i.Character == Char then
10                        game.ReplicatedStorage.RemoteEvent:FireClient(i)--this fires the remote event to that player whos gui you wanna mess with
11                        print("ED")
12                    end
13                end
14            end
15        end
16        FindChar()
17    end
18end)

then in local script:

01script.Parent.MouseButton1Click:Connect(function(clk)
02    script.Parent.Parent.Visible = false
03end)
04 
05 
06game.ReplicatedStorage.RemoveEvent.OnClientEvent:Connect(function()--this triggers when the remote event fires
07 
08    game.Players.LocalPlayer.PlayerGui.ShopGui.Shop.Visible = true
09 
10end)
0
i dont know why clicking gets rid of the gui, but you can mess with that urself :) hope this helps AlexanderYar 788 — 4y
0
IT WORKED!!!! YESSSS! TheB4dComputer 100 — 4y
0
glad i could help :3 AlexanderYar 788 — 4y
Ad

Answer this question