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

why my localscript on playergui that suppose to change a bool value on workspace didnt work?

Asked by
Annon28 23
6 years ago
Edited 6 years ago

i make a team selection gui in StarterGui. i also added a local script to make the selection screen gone and added a humanoid in player character. it did work fine until i tested it on server with 2 players. the gui did disappeared and both worked fine for 2 players but the bool value that i place on the workspace didnt change its value.

--startgame
script.Parent.choose.Defend.Activated:connect(function()
    local defend = Instance.new("Humanoid")
    defend.Name = "Defend"
    defend.Parent = game.Players.LocalPlayer.Character
    script.Parent.choose.Enabled = false
    game.Workspace.defend.Value = true
end)
script.Parent.choose.Prosecutor.Activated:connect(function()
    local prosecutor = Instance.new("Humanoid")
    prosecutor.Name = "Prosecutor"
    prosecutor.Parent = game.Players.LocalPlayer.Character
    script.Parent.choose.Enabled = false
    game.Workspace.prosecutor.Value = true
end)
--ready

1 answer

Log in to vote
0
Answered by 6 years ago

You need to fire a RemoteEvent to change a value on the server(for everyone). Local scripts only interact with the client. An example of a RemoteEvent:

ServerScript

local replicated = game:GetService("ReplicatedFirst")
local exampleevent = Instance.new("RemoteEvent")
exampleevent.Parent = replicated
exampleevent.Name = "Example"

function OnFired(plr)
plr.leaderstats.Value = plr.leaderstats.Value + 1
end

exampleevent.OnServerEvent:Connect(OnFired)

LocalScript:

local replicated = game:GetService("ReplicatedFirst")
local examplevent = replicated:WaitForChild("Example")
local player = game.Players.LocalPlayers

script.Parent.MouseButton1Click:Connect(function()
    exampleevent:FireServer(player)
end)

If you need more help then click here

0
this is something new for me. thx for the help Annon28 23 — 6y
Ad

Answer this question