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

This play button script only works In Studio and not In Server?

Asked by 6 years ago

I tested this script, and it worked, but when I test a server it doesn't work.. It's supposed to spawn the player in a specific team and load the character but it only works when I test in general in studio but in a server it doesn't work at all.. I tried to make the main script a local script but it doesn't work neither on server or on client. On server or studio there are no errors..

Main script(Parent=Workspace, ServerScript)

game.ReplicatedStorage.PlayerSpawn.OnServerEvent:Connect(function(plr)
    local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
    local t = house.PlayButton.Text
    plr.PlayerGui.GameChooseGUI.Frame.Visible = false
    plr.TeamColor = BrickColor.new("Bright red")
    plr:LoadCharacter()
    house:Destroy()
end)

GUI Script(Parent=PlayButton, LocalScript)

local plr = game.Players.LocalPlayer
local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
local t = house.PlayButton.Text
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.PlayerSpawn:FireServer()
end)

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

If the gui is in StarterGui and the game is Filtering Enabled, then the server cannot see the gui, so you cannot index it from a server script.

You should rather pass the t variable from the client using the remote event, which idk what is for in the first place if you never even use it but whatever. Same for frame visibility.

Local script:

local plr = game.Players.LocalPlayer
local house = plr.PlayerGui:WaitForChild("GameChooseGUI").Frame
local t = house.PlayButton.Text
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.PlayerSpawn:FireServer(t) --pass the t variable
    house.Visible = false --hide it on the client, not server
end)

Server script:

game.ReplicatedStorage.PlayerSpawn.OnServerEvent:Connect(function(plr, t) --you can use the t variable in this function now
    plr.TeamColor = BrickColor.new("Bright red")
    plr:LoadCharacter()
end)
0
alright! sorry for the 7-day delay but It worked mudathir2007 157 — 6y
Ad

Answer this question