Hi Everyone,
I’m making a trap system for a game similar to piggy, but it’s not working!
The weird thing is, is that when I place the trap in workspace; not using scripts, and play test, and walk into it, it works!
But it doesn’t work when it gets cloned out of ReplicatedStorage!
Clone script ( in serverscriptservice)
local function PlaceTrap(Player)
if Player:FindFirstChild('DogeTag') and game.ReplicatedStorage.Values.GameInProgress.Value == true and Player.TrapDebounce.Value == false then
if Player.TrapCount.Value > 0 then
Player.TrapDebounce.Value = true
Player.TrapCount.Value = Player.TrapCount.Value - 1
local HRP = Player.Character.HumanoidRootPart
local Trap
Trap = game.ReplicatedStorage.Traps:FindFirstChild(Player.EquippedTrap.Value):Clone()
if workspace:FindFirstChild('Map1') then
Trap.Parent = workspace.Map1
elseif workspace:FindFirstChild('Map2') then
Trap.Parent = workspace.Map2
elseif workspace:FindFirstChild('Map3') then
Trap.Parent = workspace.Map3
end
if Trap ~= nil then
print('placing trap....')
Trap.Open.CFrame = Player.Character.HumanoidRootPart.CFrame - Vector3.new(0,4.2,0)
wait(5)
Player.TrapDebounce.Value = false
else
warn('Trap not found')
end
end
end
end
Trap Script( In the trap model which is in ReplicatedStorage.):
local Trap = script.Parent
local Open = Trap.Open
local Closed = Trap.Open.Close
local HitBox = Open.Hitbox
local Connection
Connection = HitBox.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild('Humanoid') then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
local Humanoid = Hit.Parent.Humanoid
local Animation = Humanoid:LoadAnimation(workspace.TrappedAnimation)
if not Player:FindFirstChild('DogeTag') then
Connection:Disconnect()
Humanoid.JumpPower = 0
Humanoid.WalkSpeed = 0
Animation:Play()
Open.Stunned:Play()
Open.Transparency = 1
Closed.Transparency = 0
spawn(function()
wait(Open.Cooldown.Value)
Animation:Stop()
Humanoid.JumpPower = 50
Humanoid.WalkSpeed = 16
wait(3)
script.Parent:Destroy()
end)
end
end
end)
I get no errors though.
Does anyone know why it isn’t working?!!
Thanks for any help!!