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

Who can help for the leaderboard script?

Hi! I am creating a game where, when the player touches the button, the character jumps and adds 1 to the leaderboard. Unfortunately, one of the two scripts makes that only the player who clicks on the button sees his score but not the others (see the video) and I don't know how to make everyone see it, here are the two scripts: the button script:

script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	local humanoid = character.Humanoid
	if humanoid.FloorMaterial == Enum.Material.Air then return end
	humanoid.JumpHeight += 1
	player.leaderstats.JumpPwr.Value = player.leaderstats.JumpPwr.Value + 1 
	local oldJumpPower = humanoid.JumpPower
	humanoid.JumpPower = 10
	humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	humanoid.JumpPower = oldJumpPower
end)

and the leaderboard script:

local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
	if player then 
		local folder = Instance.new('Folder')
		folder.Name = 'leaderstats'
		folder.Parent = player
		local JumpPwr = Instance.new ('IntValue')
		JumpPwr.Name = 'JumpPwr'
		JumpPwr.Parent = folder
		JumpPwr.Value = 0
	end
end)

And theres the example video: https://streamable.com/a7uj6u Thanks in advance for your help and have a nice day!

3 comments

0

you are changing the value on Client (using LocalScript) this makes it only visible for this player, if you want to change for everybody you should change it on server, using RemoteEvents you can communicate with server using LocalScript

0

uWu i found your discord i spam there

0

nvm i got rejected :sob:

1 answer

✓ Accepted answer

all you have to do is create RemoteEvent in ReplicatedStorage this will be your communication channel between LocalScript and Server, then in Script (not LocalScript) you need to do a code like this:


local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')

players.PlayerAdded:Connect(function(player)
    if player then 
        local folder = Instance.new('Folder')
        folder.Name = 'leaderstats'
        folder.Parent = player
        local JumpPwr = Instance.new ('IntValue')
        JumpPwr.Name = 'JumpPwr'
        JumpPwr.Parent = folder
        JumpPwr.Value = 0
    end
end)

replicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
  if not player.Character then return end
  local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
  if not humanoid then return end
  if humanoid.FloorMaterial == Enum.Material.Air then return end
  print(player, "JumPED")
  player.leaderstats.JumpPwr.Value += 1
end)

this event will be triggered when LocalScript triggers, LocalScript will trigger it when you press the button, that means in your LocalScript you have to stuff like this:


local replicatedStorage = game:GetService('ReplicatedStorage')

script.Parent.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character
    local humanoid = character.Humanoid
    if humanoid.FloorMaterial == Enum.Material.Air then return end
    humanoid.JumpHeight += 1
    --player.leaderstats.JumpPwr.Value = player.leaderstats.JumpPwr.Value + 1 
    -- this will trigger the RemoteEvent on server
    replicatedStorage.RemoteEvent:FireServer()
    local oldJumpPower = humanoid.JumpPower
    humanoid.JumpPower = 10
    humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    humanoid.JumpPower = oldJumpPower
end)

if you done with this then there is important issue that is that exploiters can spam :FireServer which will give him BIG jump power, in order to avoid that you should also check on Server whether player.Character.Humanoid is not in Air as you did in LocalScript.

6 comments

0

Hi! I followed all your instructions but when I go to the test, it still does not work, here is a video:https://streamable.com/43e8av

0

you didn't see output for errors :Z line 20 in server script, change == to ~=, if that won't work then remove it completely, that should solve it

0

@wDaerkfeX

0

I didn't create a script in server script?

0

@wDaerkfeX the leaderboard script is a server script

0

Oh sry XD

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