Money to Walkspeed script not working!

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:

2nd

Thank you for seeing this!

I did not know that I could do that. Thank you for telling me!

1 Like

This should fix it

local Speed = game.StarterPlayer.Humanoid.WalkSpeed
local money = game.ServerScriptService.PlaceHolder.leaderstats.Coins.Value

if money >= 100 then
    -- function
end

Let me go test it. I hope it does work!

It didn’t work, sadly. Thank you for helping though!

Changing == to >= is just one of the issues, though.

Here’s some more (there may be more):

  1. game.StarterPlayer refers to the template that all Players are copied from, not the actual current player.
  2. Humanoid is a property of Player.Character, not Player
  3. This script only runs once when the game starts. Nothing will happen if money changes later.
  4. This script runs on the server. To access players, you’ll need to loop through them.
  5. 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”).
2 Likes

Wait what are you trying to do? Change the player’s walkspeed if they have more than 100 coins?

1 Like

try

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

Yes, kind of like an easier upgrade system.

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)

EDIT: Oops meant to reply to @Dev_BB1

The player doesn’t come from StarterPlayer so Humanoid won’t be found there.

I don’t understand why your leaderstats are located here

game.Players.PlayerAdded:Connect(function(player)
    local folder = Instance.new('Folder')
    folder.Parent = player
    folder.Name = 'leaderstats'

    local money = Instance.new('IntValue')
    money.Parent = folder
    money.Name = 'Coins'

    player.CharacterAdded:Connect(function(char)
        local speed = char.Humanoid.WalkSpeed
        if money.Value >= 100 then
             print('works')
             speed = 20
        end
    end)
end)

Fixed it! It might be a little easier to fix now.

:thinking: It still won’t change the walkspeed. I put the humanoid inside StarterPlayer. Maybe that could have an impact?

Ok so here’s the fixed script.

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)

Here’s an image of the explorer too:
image

You can shorten that into a few lines of code. Give me a min to rewrite.

I bet i could help, how mutch walkspeed for how mutch money, or per dollar how mutch walkspeed?

100 dollars = 60 walkspeed. That’s the amount.

Do you have a script which adds money to the player’s coins? Of course it won’t work if nothing is adding because the value will be 0

okay, i will make a script for that

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)

That should work

1 Like