Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isnt my localscript giving that player its taps?

Do I have to use a normal script for this?

local taps = 0
local tapgive = 1

--Tap Loader
spawn(function()
	taps = game.Players.LocalPlayer.leaderstats.Taps.Value
	script.Parent.TapGui.Frame.TextLabel.Text = taps .." taps"
end)

function tapclick()
	taps = game.Players.LocalPlayer.leaderstats.Taps.Value
	taps = taps + tapgive
	game.Players.LocalPlayer.leaderstats.Taps.Value = game.Players.LocalPlayer.leaderstats.Taps.Value + tapgive
	script.Parent.TapGui.Frame.TextLabel.Text = taps .." taps"
end

script.Parent.TapGui.TextButton.MouseButton1Click:Connect(tapclick)

I went to client while running game and it said 0 when in server-client it said more than 0

1 comment

0

you can't change leaderstats using localscript as it won't replicate

1 answer

First off, spawn() is deprecated; you should use coroutine.wrap().

Also, you can't modify LeaderStats from the client. You would need to make a RemoteEvent in Replicated Storage (or any other place that both the client and the server can see) and make a server script somewhere (ideally in ServerScriptStorage just for organization) that detects when you want to update a LeaderStat.

I usually do something like this

LocalScript

local statEvent = game.ReplicatedStorage.UpdateLeaderStats

statEvent:FireServer("Taps", game.Players.LocalPlayer.leaderstats.Taps.Value+tapgive)

Server Script

local statEvent = game.ReplicatedStorage.UpdateLeaderStats

statEvent.OnServerEvent:Connect(function(player, name, value)
	local leaderstats = player.leaderstats
	leaderstats[name].Value = value
end)

This way, you can use any client-side script to change the leaderstats by just putting in the name of the leaderstat and the value you want it set to as the tuple arguments.

2 comments

0

@MysticAviator, so i should change spawn(autosave) in my data store to coroutine.warp(autosave) ?

0

To have the autosave function running in the background ^

This discussion is preserved as it was. New answers, comments, and votes are closed.