Ad
Log in to vote
0

How to make to add points from jump?

Asked by 5 days ago

I am trying to make parkour game but this not working, can somebody help me?

local Points = game.Players.LocalPlayer
local Players = game:GetService("Players")

local function JumpAddPoints(player)
    if script.Parent.Humanoid.Jump == true then
        Points.leaderstats.Points.Value = Points.leaderstats.Points.Value + 3
    end
end


game.Players.PlayerAdded:Connect(Players)

1 answer

Log in to vote
0
Answered by 5 days ago

You can not change leaderstats from LocalScript, what you should use is Remote Servers.

LocalScripts only work on servers so whenever you change something from localscript it will only change to that player, what you should do is use RemoteEvent to send signal from localscript and then get that signal at serverscript and then do whatever u want. Here are steps:

1)Place RemoteEvent in ReplicatedStorage and name it Jump

2)Make LocalScript in StarterPlayerScripts Put this script in LocalScript

local Player = game.Players.LocalPlayer --we get player(this only works at localscript)
local character = Player.Character or Player.CharacterAdded:Wait() --We get player model
local Humanoid = character:FindFirstChild("Humanoid") -- we get Humanoid
local jumpevent = game.ReplicatedStorage.Jump --remote event

Humanoid:GetPropertyChangedSignal("Jump"):Connect(function(changed)  -- checks if jump property changed
    if changed and Humanoid.Jump == true then --if when it changed it became true
           jumpevent:FireServer()
    end)
end

3)Make Script in ServerScriptService Put this script Inside

local jumpevent = game.ReplicatedStorage.Jump --remote event

jumpevent.OnServerEvent:Connect(function(player) --if that remote event is fired
    player.leaderstats.Points.Value += --whatever amount you want
end)

I have not checked code, tell me if there are any errors

0
It's actually not working, i checked everything and it wasn't saying any errors in Output and even in console too as well. I did everything as you said. SoftBlueApple -2 — 5d
Ad

Answer this question