Why is this not working?

Ths secripts goal is so that if someone goes through it with a car they get + 800 cash. But it does not work. I want it so that there is a part at the finish line and the person that goes through in a car gets the 800 cash Here is the script:

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 800
end
end)

I also think theres something wrong with the leaderboard script its main job is to give money so you can buy cars and to save your total money.

local DataStoreService = game:GetService(“DataStoreService”)
local PlayerCash = DataStoreService:GetDataStore(“PlayerCash”)

function OnPlayerAdded(player)
local stats = Instance.new(“Folder”, player)
stats.Name = ‘leaderstats’
local Cash = Instance.new(“IntValue”, stats)
Cash.Name = “$”
Cash.Value = 150000
local data
local success, err = pcall(function()
data = PlayerCash:GetAsync(player.UserId)
end)
if success then
print(“Data loaded!”)
if data then
Cash.Value = data
end
else
print("There was an error while getting data of player " … player.Name)
warn(err)
end
while true do
wait(180)
Cash.Value = Cash.Value +100
end
end

function OnPlayerRemoving(player)
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild(“$”).Value)
end)
if success then
print(“Data saved!”)
else
print("There was an error while saving data of player " … player.Name)
warn(err)
end
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)

A alternative would be making a finish line that gives you cash.

For plr.leaderstats.Cash.Value = +800 it needs to be plr.leaderstats.Cash.Value += 800

1 Like

This.

plr.leaderstats.Cash.Value += 800
1 Like

Didnt work in the game at all.

niether of yours

do

plr.leaderstats.Cash.Value += 800

that will work.

script.Parent.Touched:Connect(function(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
       local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
       plr.leaderstats.Cash.Value += 800
  end
end

That should work.

Nope didnt work.

I probaly should have put this in the post but I want a part that you can go through to then earn 800 cash in game.

I have the part not the script.

Did my 2nd reply work? Or do you get any errors?

Nope didnt work.

Am I doing something wrong with the part.

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
	print("i found the humanoid!")
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	plr.leaderstats.Cash.Value += 800
end
end)

i tried this and it worked.

I think you did something wrong with the part yes.

But what is wrong with it.

How does your part look?

image

What are its Properties?
Like is Cancollide on and what not.

I think it might be my leaderstats script it says:
local DataStoreService = game:GetService(“DataStoreService”)
local PlayerCash = DataStoreService:GetDataStore(“PlayerCash”)

function OnPlayerAdded(player)
local stats = Instance.new(“Folder”, player)
stats.Name = ‘leaderstats’
local Cash = Instance.new(“NumberValue”, stats)
Cash.Name = “$”
Cash.Value = 0
local data
local success, err = pcall(function()
data = PlayerCash:GetAsync(player.UserId)
end)
if success then
print(“Data loaded!”)
if data then
Cash.Value = data
end
else
print("There was an error while getting data of player " … player.Name)
warn(err)
end
while true do
wait(2)
Cash.Value = Cash.Value +0
end
end

function OnPlayerRemoving(player)
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild(“$”).Value)
end)
if success then
print(“Data saved!”)
else
print("There was an error while saving data of player " … player.Name)
warn(err)
end
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)

OHHHH i see it. You have to do plr.leaderstats[“$”].Value += 800.

because the name of the value is “$”

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
print(“i found the humanoid!”)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.[“$”].Value += 800.
end
end)

This not working.

In the leaderstats script, change “NumberValue” to “IntValue”.

The part still didnt work after changing that.