Invalid argument #3 (string expected, got Instance)?

invalid argument #3 (string expected, got Instance) ?

I am using proximity prompt to make the player sit on my car seat and detect who the player is. When I do that using the script.Parent.Touched:Connect(function(hit) it doesn’t detect anyone sitting so I have moved on to detecting straight from the proximity prompt and then storing that value on a string value but when I run my code it gives me the invalid argument #3 (string expected, got Instance) ? Does anyone know how to fix this?

- Hit function Script

local player
local MetersDriven = script.Parent.MetersDriven

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		print("Touched")
		player = game.Players:GetPlayerFromCharacter(hit.Parent)
	end
end)

while true do
	MetersDriven.Value = MetersDriven.Value + script.Parent.Velocity.Magnitude
	if MetersDriven.Value > 1609 then
		MetersDriven.Value = 0
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + script.Parent.MoneyPM.Value
		player.leaderstats.Miles.Value = player.leaderstats.Miles.Value + 1
	end 
	wait(1)
end

- Proxi Script

local playerSeat = script.playerSeat.Value
local MetersDriven = script.Parent.MetersDriven

script.Parent.ProximityPrompt.TriggerEnded:Connect(function(plr)
	playerSeat = plr
end)

while true do
	MetersDriven.Value = MetersDriven.Value + script.Parent.Velocity.Magnitude
	if MetersDriven.Value > 1609 then
		MetersDriven.Value = 0
		playerSeat.leaderstats.Cash.Value = playerSeat.leaderstats.Cash.Value + script.Parent.MoneyPM.Value
		playerSeat.leaderstats.Miles.Value = playerSeat.leaderstats.Miles.Value + 1
	end 
	wait(1)
end

Thanks for the help!

For the first Hit script as I can see you have used no coroutines or spawn or delay which allow the other parts of the script to run independently.
Because the while loop is constantly running ay other part of the script is not getting executed.

For the second script.
You have set an Instance as the string value.
It will be like this:
StringValue.Value = Player.Name
If you want to set the player as the value use object value instead

1 Like