I'm trying to make a placement system that clones a model from the local script in ReplicatedStorage, parents it to a folder in the workspace, fires a remote event to the server so the server can clone "t", fires back a remote event towards the client to get the client to delete the original model, fires another remote event towards the server to get it to edit the position of the clone, and once the player presses the left mouse button, it places the model right where the mouse is. The problem is that the server never clones "t" and gives this error:
ServerScriptService.Scripts.EventController:25: attempt to index local 'p1' (a nil value)
How do I get p1 to stop being nil? (p1 is the name of the "t" value in the server script)
Server script:
signal.OnServerEvent:Connect(function(plr,ver,p1,p2,p3,p4)
local bdfl = {
CloningEvent = function(p1,p2)
print(p1,p2)
if p1 ~= nil then --to find the error that I shoved above just remove the if, else and the end for them because this checks if p1 is not nil meaning that no error will output (set it like this because it always spammed my output when i was trying to test other things)
print("works")
local newClone = p2:Clone()
newClone.Parent = gs.CurrentCourse.Turrets
cloneEvent:FireClient("Backdoor",p1,p2)
else
print("p1 most likely nil again :|")
end
end,
UpdateTurretPosition = function(p2,p3) --the new p2 and p3 updated by cloningEvent
if p2 == nil then
if p2:IsA('Model') then
p2:SetPrimaryPartCFrame(p3)
elseif p2:IsA('BasePart')then
p2.CFrame = p3
end
end
end
}
if ver == "Backdoor" then
bdfl[p1](p2,p3,p4)
end
end)
Local Script
signal.OnClientEvent:Connect(function(ver,p1,p2,p3,p4)
local bdfl = {
SetupTurret = function()
local clp = true --Currently placing
local lastrot = {
x=0,
y=0,
z=0,
}
local t = game.ReplicatedStorage.Assets.Turrets.Wizard:Clone()
t.Parent = gs.CurrentCourse.Turrets
-- towerNum = 1
mouse.Button1Down:Connect(function() --this places the model down
clp = false --Finished placing
end)
mouse.TargetFilter = t
rs:Connect(function() --rs is render stepped
if clp == true then
if mouse.target ~= nil then
if mouse.Target.Parent.Parent == gs.CurrentCourse then --gs is a module script called game settings in serverscriptservice and currentcourse is the parent of the model that is being placed
print(t) --i printed t to make sure that t actually has a value and it outputed: Wizard but after i sent the fireserver, t somehow ended up nil...
signal:FireServer("Backdoor", "CloningEvent", t, CFrame.new(mouse.Target.Position.X, ((t.PrimaryPart.Size.Y/2)+mouse.Target.Position.Y)+0.5, mouse.Target.Position.Z)*CFrame.Angles(0,lastrot.y,0))
end
end
end
end)
local function onCloneEventFired(p2,p3)
signal:FireServer("Backdoor", "UpdateTurretPosition", p2, p2.Position, p3)
p2:Destroy()
end
end
if ver == "Backdoor" then
bdfl[p1](p2, p3, p4) --bdfl is backdoor function list
elseif ver == "Frontdoor" then
signal:FireServer("Backdoor", p1, p2, p3,p4)
end
end)

2 comments
Did you copy the code? :connect is deprecated use :Connect
It is? Thought it didnt matter. Well mb then, been a long time since I last used roblox lua