✓ Accepted answer
The issue is that when the part touches something you invoke the client whether its a character or not because its not within the if part.Parent:IsA("Model") scope so it errors with argument missing or nil.
What we first want to do is fix up that detection as not all models are characters so we can just detect if it has a humanoid in its model, then we set the character to humanoid's parent, and we also set the plr using getplayerfromcharacter function.
local db = true
local OpenLoad = game.ReplicatedStorage.BuyCar.BuyCar2
local char = nil
local plr = nil
script.Parent.Touched:Connect(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid then
char = part.Parent
plr = game.Players:GetPlayerFromCharacter(char)
end
end)
Now that we have successfully detected the character and verified that it is indeed a character we can go on ahead with the code you already have,
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid then
char = part.Parent
plr = game.Players:GetPlayerFromCharacter(char)
if db == true then
db = false
OpenLoad:InvokeClient(plr)
wait(1)
db = true
end
end
And the server script looks fine to me so I don't think there are any issues with that, after all the edits above your script should look something like this (Please remember like I always say to read through and understand what I said before as it will be more beneficial and make sure to not just copy the final script).
local db = true
local OpenLoad = game.ReplicatedStorage.BuyCar.BuyCar2
local char = nil
local plr = nil
script.Parent.Touched:Connect(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid then
char = part.Parent
plr = game.Players:GetPlayerFromCharacter(char)
if db == true then
db = false
OpenLoad:InvokeClient(plr)
wait(1)
db = true
end
end
end)
Make sure to comment if there are still any errors or questions/concerns you may have! And mark this as the answer if it helped you!
2 comments
Thank you!
No problem :)