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

Who can help for the leaderboard script?

Asked by 2 years ago
Edited 2 years ago

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!

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 imKirda 4491 — 2y
0
uWu i found your discord i spam there imKirda 4491 — 2y
0
nvm i got rejected :sob: imKirda 4491 — 2y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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.

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 wDaerkfeX 37 — 2y
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 imKirda 4491 — 2y
0
@wDaerkfeX imKirda 4491 — 2y
0
I didn't create a script in server script? wDaerkfeX 37 — 2y
View all comments (2 more)
0
@wDaerkfeX the leaderboard script is a server script imKirda 4491 — 2y
0
Oh sry XD wDaerkfeX 37 — 2y
Ad

Answer this question