Hello! So I recently made a game I’m working on multiplayer, and I wanted to make it so only one person can claim a character, so I tried creating a script to do that, basically, if a Intvalue in Workspace has a value of 0, then whenever someone clicks a button, it enables the script and changes the Intvalue to 1. However, the script does work, but it doesn’t change the text of the button. I am unable to get it to work, so I came here for help!
Script:
local RemoteEvent = game:GetService("ReplicatedStorage").FireChar
local HumanoidDescription = workspace.Morph["Morph Script"].Settings:FindFirstChildOfClass("HumanoidDescription")
RemoteEvent.OnServerEvent:Connect(function(Player)
if game.Workspace.Value1.Value == 1 then
game.StarterGui.LoadingScreen.Frame2.Bob.Text = "Taken"
wait(4)
game.StarterGui.LoadingScreen.Frame2.Bob.Text = "Bob"
else
game.StarterGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = false
Player.Character.Humanoid:ApplyDescription(HumanoidDescription)
game.Workspace.Value1.Value = 1
end
end)
You are using the StarterGui which would only change the gui at the start, would have to use a LocalScript to access the PlayerGui and do something like this:
local RemoteEvent = game:GetService("ReplicatedStorage").FireChar
local HumanoidDescription = workspace.Morph["Morph Script"].Settings:FindFirstChildOfClass("HumanoidDescription")
RemoteEvent.OnServerEvent:Connect(function(Player)
for i,v in pairs(game:GetService("Players").GetPlayers()) do
if game.Workspace.Value1.Value == 1 then
v.PlayerGui.LoadingScreen.Frame2.Bob.Text = "Taken"
wait(4)
v.PlayerGui.LoadingScreen.Frame2.Bob.Text = "Bob"
else
v.PlayerGui.LoadingScreen.Frame2.Bob.LocalScript.Disabled = false
Player.Character.Humanoid:ApplyDescription(HumanoidDescription)
game.Workspace.Value1.Value = 1
end
end
end)
StarterGui is used as a template for the UI the player sees. If you change something in StarterGui, the player would need to rejoin to actually see the change. The UI the player can actually see is located in Player.PlayerGui.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
-- Now the script for LocalScript
RemoteEvent.OnClientEvent:Connect(function (Text)
TextLabel.Text = Text
end)
-- Now script for ServerScript
RemoteEvent:FireClient("Taken")
wait(4)
RemoteEvent:FireClient("Bob")
-- Or
-- Now the script for LocalScript
RemoteEvent.OnClientEvent:Connect(function (Number)
if Number == 1 then
TextLabel.Text = "Taken"
wait(4)
TextLabel.Text = "Bob"
end
end)
-- Now script for ServerScript
RemoteEvent:FireClient(1)