Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I just made a copy and modified my script then it errored?

this is the script for the touch part where i let the script detect if the part is touched then it should show a gui,my first one worked but when i made a copy of it and modified it abit it tells the error. Here is the script in the part:

local db = true
local OpenLoad = game.ReplicatedStorage.BuyCar.BuyCar2
local char = nil

script.Parent.Touched:Connect(function(part)
	if part.Parent:isA("Model") then
		char = part.Parent
	else
		char = part.Parent.Parent
	end
	local plr = game.Players:GetPlayerFromCharacter(char)
	if db == true then
		db = false
		OpenLoad:InvokeClient(plr)
		wait(1)
		db = true
	end
end)

Here is the script in the Gui Frame:

local Load = game.ReplicatedStorage.BuyCar.BuyCar2

Load.OnClientInvoke = function(plr)
	script.Parent.Visible = true
end

Error: Argument 1 missing or nil

1 answer

✓ 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") --checking or trying to find a humanoid inside of the part's parent
	if Humanoid then --now we confirm there is a humanoid inside of the model
		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

1

Thank you!

0

No problem :)

This discussion is preserved as it was. New answers, comments, and votes are closed.