So I’m trying to make text change for my chests from “Collect!” to “Can’t Collect!” and vice versa, and it will be different for the player, but LocalScripts do not run in the Workspace.
So when you collect the chest, it will change to “Can’t collect!”, and when the chest is ready again, it’ll change back to “Collect!”
local text1 = "Collect"
local text2 = "Can't collect"
--Be sure to define "textlabel"
if textlabel.Text == text1 then
textlabel.Text = text2
elseif textlabel.Text == text2 then
textlabel.Text = text1
end
local chest = --define chest here
local remote = --define remote event here
chest.Touched:Connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
remote:FireClient(player)
end)
And in a local script, type the following:
local remote = --define remote event here
local textlabel = --define textlabel here
local opened = "Collect"
local closed = "Can't Collect"
remote.OnClientEvent:Connect(function()
if textlabel.Text == opened then
textlebel.Text = closed
--give the player whatever they want here (if it is a tool, you may want to fire another remote event to the server so it shows up for everyone else in the server)
wait(20) --Cooldown time until chest is collectable again
textlabel.Text = opened
end
end)
Oh also, for the textlabel, you may want to get it from the player’s PlayerGui, as opposed to the StarterGui
local player = game.Players.LocalPlayer
local textlabel = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TextLabel")
--define it properly as how you named your textlabel and its parents
Ohh, i see (I’m assuming you just use a boolvalue for if you opened it or not) Do this instead:
ServerScript:
local chest = --define chest here
local remote = --define remote event here
chest.Touched:Connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
local daily = player:FindFirstChild("Opened") --define this properly (i would recommend making this a BoolValue)
if daily.Value == false then
daily.Value = true
remote:FireClient(player)
--reward player here
end
end)
LocalScript:
local remote = --define remote event here
local textlabel = --define textlabel here
local opened = "Collect"
local closed = "Can't Collect"
remote.OnClientEvent:Connect(function()
if textlabel.Text == opened then
textlebel.Text = closed
end
end)
Don’t use DataStore on a localscript. I’m pretty sure it won’t work. If you have to, use remote events (client to server) to save data (unless if ur already on a serverscript)
Since you are changing the BoolValue to true from the serverscript and changing the textlabel from a local script, the server recognizes that the player has obtained the reward and fires a message to the client, which changes their textlabel
So you’re using SurfaceGui’s? if so, then put a localscript in StarterPlayer (so the localscript goes in the player object). make a touched event and fire a remove event to the localscript and change the text on the localscript. Be sure to carry the textlabel over to the localscipt.
--SERVERSCRIPT
local chest = script.Parent? --make sure that this is a part and not a folder/model
local textlabel = chest:WaitForChild('SurfaceGui'):WaitForChild('TextLabel') --redefine this to the textlabel
local remoteEvent = --define remove event here
chest.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
remoteEvent:FireClient(plr,textlabel)
end
end)
--LOCALSCRIPT
local remoteEvent = --define remote event here
local text1 = "Collect"
local text2 = "Can't collect"
remoteEvent.OnClientEvent:Connect(function(textlabel)
if textlabel.Text == text1 then
textlabel.Text = text2
elseif textlabel.Text == text2 then
textlabel.Text = text1
end
end)
To make it change back, whenever your cooldown is up, you can just set’s the player’s Opened value back to false and fire a remote event to that client that changes the textlabel back to “Collect”