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
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
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 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
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)