I have a script in a part that gets cloned to Workspace. When you get the health of the part to 0, another part in Workspace is cloned to the player’s position.
Then a remote event is fired that makes the transparency of the part 0 for the player who got the health of the part to 0.
The issue is in my LocalScript inside StarterPlayerScripts, I am getting the error: “Argument 1 missing or nil”
How do I fix this?
Part Script:
function Dead()
local Humanoid = script.Parent.Humanoid
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local plr = tag.value
local Part = game.Workspace.Folder.Part:Clone()
Part.Position = script.Parent.HumanoidRootPart.Position
Part.Anchored = false
Part.Parent = game.Workspace.Folder
game.ReplicatedStorage.RemoteFolder.Remote:FireClient(plr, Part)
end
end
end
LocalScript:
game.ReplicatedStorage.RemoteFolder.Remote.OnClientEvent:Connect(function(plr, Part)
local Part1 = game.Workspace.Folder:FindFirstChild(Part)
Part1.Transparency = 0
end)
The plr argument in FireClient is used to determine which player’s remote event to trigger, it’s not passed to the client, meaning that part was being assigned to the plr parameter in your OnClientEvent function. If you remove the plr parameter, it’ll work.
game.ReplicatedStorage.RemoteFolder.Remote.OnClientEvent:Connect(function(Part)
local Part1 = game.Workspace.Folder:FindFirstChild(Part)
Part1.Transparency = 0
end)
Remove the Player Argument on the Client Event
So Like this:
Local Script:
game.ReplicatedStorage.RemoteFolder.Remote.OnClientEvent:Connect(function(Part)
local Part1 = game.Workspace.Folder:FindFirstChild(Part)
Part1.Transparency = 0
end)
Server Script
function Dead()
local Humanoid = script.Parent.Humanoid
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local plr = tag.value
local Part = game.Workspace.Folder.Part:Clone()
Part.Position = script.Parent.HumanoidRootPart.Position
Part.Anchored = false
Part.Parent = game.Workspace.Folder
game.ReplicatedStorage.RemoteFolder.Remote:FireClient(plr, Part)
end
end
end