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

whenever i click with the tool on the screen, the points in the leaderboard dont add up?

Asked by 3 years ago

game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new ("Folder",player)
leaderstats.Name = "leaderstats" local points = Instance.new ("IntValue",leaderstats) points.Name = "points"

end)

game.StarterPack.swordtool:Activate(function(hit) local playerpoints = game.leaderstats.points if hit then playerpoints.Value = playerpoints.Value + 1 end end)

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

Tools in StarterPack are simply there to be (automatically) cloned into each player's backpack.

Also, you are inconsistent with where the leaderstats folder is stored. In the first section, you parent the folder to the player. In the second section, you are getting the leaderstats folder from game (you were right in the first section, it should be parented to the player).

The best way to add points to the player's leaderstats would be to use a RemoteEvent.

To do this, you would fire an event from the client (local script) to the server and request points to be added to the player's leaderboard stat.

Server-side:

local pointsEvent = -- Location of remote event

event.OnServerEvent:Connect(function(player)
    player.leaderstats.points.Value += 1
end)

Client-side:

local tool = script.Parent
local pointsEvent = -- Location of remote event
tool.Activated:Connect(function()
    event:FireServer()
end)
Ad

Answer this question