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!
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.