Hi!
I’m making a new game and I want to spawn things based on which button a user presses, the value for which tower to spawn is set by another function.
Set towertospawn value
local function addpt(name)
local towerexists = towers:FindFirstChild(name)
if towerexists then
removept()
towertospawn = towerexists:Clone()
print(towertospawn.Name)
towertospawn.Parent = workspace.Towers
for i, object in ipairs(towertospawn:GetDescendants()) do
if object:IsA("BasePart") then
ps:SetPartCollisionGroup(object, "tower")
object.Material = Enum.Material.ForceField
object.Color = Color3.new(0,1,0)
end
end
end
end
Create buttons and create tower preview
for i, tower in pairs(towers:GetChildren()) do
local button = gui.Frame.Placeholder:Clone()
button.Name = tower.Name
print(tower.Name)
button.Parent = gui.Frame
button.Activated:Connect(function()
addpt(tower.Name)
print(tower.Name)
end)
end
Create tower via remote event (sending info)
uis.InputBegan:Connect(function(input, processed)
if processed then
return
end
if towertospawn then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if placeable == false then
print("not placeable")
elseif placeable == true then
local name = towertospawn.Name
print(name)
event:FireServer(towertospawn.PrimaryPart.CFrame, towertospawn.Name)
removept()
end
elseif input.KeyCode == Enum.KeyCode.R then
rot += 90
end
end
end)
There are no errors, except this part:
event:FireServer(towertospawn.PrimaryPart.CFrame, towertospawn.Name)
There is not an error, I set it to print towertospawn.Name and it prints the correct name but when I use a modulescript to recieve and spawn the tower, when I print the tower name it prints my username.
This is part of a function:
function tower.spawn(towername, cframe)
print("tower placed")
print(towername)
print(cframe)
local towerexists = rep.Towers:FindFirstChild(towername)
if towerexists then
local newtower = towerexists:Clone()
newtower.HumanoidRootPart.CFrame = cframe
newtower.Parent = workspace.Towers
newtower.HumanoidRootPart:SetNetworkOwner(nil)
...
end
event.OnServerEvent:Connect(tower.spawn)
^^^ Triggered by event but recieves my username instead of tower