Hi, so I have these tokens in my game, and currently use a script instead of local, I am not quite sure how I should make them local, if you know, please let me know.
Code:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr.leaderstats then
local part = script.Parent
part.Front.Transparency = 1
part.Back.Transparency = 1
part.SFX:Play()
part.CanTouch = false
plr.leaderstats.Tokens.Value += 1
wait(math.random(15, 60))
part.Front.Transparency = 0
part.Back.Transparency = 0
part.CanTouch = true
end
end
end) ```
Tbh, it will probably be quite simple to make it local:
local player == game.Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr == player then
if plr.leaderstats then
local part = script.Parent
part.Front.Transparency = 1
part.Back.Transparency = 1
part.SFX:Play()
part.CanTouch = false
RemoteEvent:FireServer()
wait(math.random(15, 60))
part.Front.Transparency = 0
part.Back.Transparency = 0
part.CanTouch = true
end
end
end)
Note that you can not change the leaderstats locally, so you have to use a remote event. Create a remote event in replicated storage, and put the below code in a server script located inside of serverscriptservice
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(plr)
plr.leaderstats.Tokens.Value += 1
end)
Oh, thank you! So the bottom script will go into the token and the top will be a local script in servicescriptservice? Sorry I’m not quite sure where I put it.
Keep the remote event and the server script the same, but have this be the local script, located in StarterPlayerScripts:
local player == game.Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
for _, Token in ipairs(game.Workspace.Tokens:GetChildren()) do
Token.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr == player then
if plr.leaderstats then
local part = script.Parent
part.Front.Transparency = 1
part.Back.Transparency = 1
part.SFX:Play()
part.CanTouch = false
RemoteEvent:FireServer()
wait(math.random(15, 60))
part.Front.Transparency = 0
part.Back.Transparency = 0
part.CanTouch = true
end
end
end)
end