Hi everyone! I currently have a school project involving me creating a roblox game and it’s due in 3 days. I am having major issues with a script of mine that calculates how much money you have and changes your walkspeed depending on the amount. For some reason, roblox studio won’t give me any error messages. I tried using the print command in the script but that didn’t pop up either. I would like to know if any of you can help me fix the script below:
local Speed = game.StarterPlayer.Humanoid.WalkSpeed
local money = game.ServerScriptService.PlaceHolder.leaderstats.Coins
if money.Value >= 100 then
end
If you would like to know where the value is coming from, here it is:
local Speed = game.StarterPlayer.Humanoid.WalkSpeed
local money = game.ServerScriptService.PlaceHolder.leaderstats.Coins.Value
if money >= 100 then
-- function
end
Changing == to >= is just one of the issues, though.
Here’s some more (there may be more):
game.StarterPlayer refers to the template that all Players are copied from, not the actual current player.
Humanoid is a property of Player.Character, not Player
This script only runs once when the game starts. Nothing will happen if money changes later.
This script runs on the server. To access players, you’ll need to loop through them.
Speed = 20 changes the variable, not the actual walkspeed. You need to actually do player.Character.Humanoid.WalkSpeed (once you figure out how to get “player”).
local Speed = game.StarterPlayer.Humanoid.WalkSpeed
local money = game.ServerScriptService.PlaceHolder.leaderstats.Coins
if money.Value >= 100 then
end
or
local Speed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
local money = game.Players.LocalPlayer.leaderstats.Coins
if money.Value >= 100 then
-- script
end
First, you have to make the folder parented to the player, and then once something happens (like a touched event) you want to check if the player’s money is greater than 100 then set it’s walkspeed to 20 (or use addition to make it work multiple times)
Here’s how i made it, it adds to the money value if the player clicks on a button.
Hopefully this will help you
-- server script
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"
local money = Instance.new("IntValue",folder)
money.Name = "Money"
for _, player in pairs(game.Players:GetPlayers()) do
if player:FindFirstChild("leaderstats") then
money:GetPropertyChangedSignal("Value"):Connect(function()
if money.Value >= 100 then
player.Character.Humanoid.WalkSpeed = money.Value / 2
end
end)
end
end
end)
local event = game.ReplicatedStorage:WaitForChild(remote event name here)
event.onServerEvent:Connect(function(plr)
local player = game.Players[plr.Name]
if player:FindFirstChild("leaderstats") then
player:FindFirstChild("leaderstats").Money.Value = player:FindFirstChild("leaderstats").Money.Value + 25
end
end)
-- local script
local event = game.ReplicatedStorage. <-- remote event name here
script.Parent.MouseButton1Click:Connect(function()
event:FireServer()
end)
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"
local money = Instance.new("IntValue",folder)
money.Name = "Money"
money:GetPropertyChangedSignal("Value"):Connect(function()
if money.Value >= 100 then
plr.Character.Humanoid.WalkSpeed = money.Value / 2
end
end)
end)
local event = game.ReplicatedStorage:WaitForChild(remote event name here)
event.onServerEvent:Connect(function(plr)
if not game.Players[plr.Name] then return end
local player = game.Players[plr.Name]
if player:FindFirstChild("leaderstats") then
player:FindFirstChild("leaderstats").Money.Value = player:FindFirstChild("leaderstats").Money.Value + 25
end
end)
-- local script
local event = game.ReplicatedStorage. <-- remote event name here
script.Parent.MouseButton1Click:Connect(function()
event:FireServer()
end)