Hey there!
So currently I’m making a drive for cash script, but I have run into some problems.
I am getting a Argument 1 missing or nil error and I don’t know why.
The script is placed inside the collider and finds the driver or player, whatever you want to call it.
The line player.leaderstats.cash.value works.
local player
local Distance = script.Distance
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
end
end)
while true do
wait(1)
local DistanceCash = require(game.ServerScriptService.DistanceCash)
local PlayerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player)
-- local PlayerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player)
-- print(PlayerMoney.Value)
Distance.Value = Distance.Value + script.Parent.Velocity.Magnitude
if Distance.Value > 100 then
--player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + DistanceCash.C46
PlayerMoney.Value = PlayerMoney.Value + 100
player.leaderstats.Distance.Value = player.leaderstats.Distance.Value + 0.1
Distance.Value = 0
end
end
When I type in the script print player, it prints my name “SuperiusSolutions”, so it know that I am the driver.
I tried to do a findfirstchild(player) in the hopes it would find the correct name in my folder, but no luck.
Thank you all so much for the fast answers! Exactly what I needed!
local player
local Distance = script.Distance
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
end
end)
while true do
wait(1)
if player then
local DistanceCash = require(game.ServerScriptService.DistanceCash)
local PlayerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
-- local PlayerMoney = game.ServerStorage.PlayerMoney:FindFirstChild(player)
-- print(PlayerMoney.Value)
Distance.Value = Distance.Value + script.Parent.Velocity.Magnitude
if Distance.Value > 100 then
--player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + DistanceCash.C46
PlayerMoney.Value = PlayerMoney.Value + 100
player.leaderstats.Distance.Value = player.leaderstats.Distance.Value + 0.1
Distance.Value = 0
end
end
end