My script is not working

local Trap = game.ServerStorage.BearTrap
local Character = script.Parent.Parent
local Player = game.Players:playerFromCharacter(Character)

function plant()
local PlacedTrap = Trap:Clone()
local PlacePos = Character.PrimaryPart.Position
PlacedTrap.Position = Vector3.new(PlacePos.x, PlacePos.y-2,PlacePos.z)
end
script.Parent.Parent.Activated:connect(plant)

ServerStorage:

image

i am trying to make a tool that places trap down and it not working somehow, I’m really bad at scripting, any reply is appreciated :slight_smile: .

everything you clone needs to be parented to something

local Trap = game.ServerStorage.BearTrap
local Character = script.Parent.Parent
local Player = game.Players:playerFromCharacter(Character)

function plant()
	local PlacedTrap = Trap:Clone()
	local PlacePos = Character.PrimaryPart.Position
	PlacedTrap.Parent = workspace
	PlacedTrap.Position = Vector3.new(PlacePos.x, PlacePos.y-2,PlacePos.z)
end
script.Parent.Activated:connect(plant)
1 Like

You need to parent it to workspace. Add PlacedTrap.Parent = workspace before you position it.

not working still somehow, I don’t see any problem here.

This needs to be:

local Player = game.Players:GetPlayerFromCharacter(Character)

Edit: on second read, this is pointless because you don’t even use the player variable.

i think my scripting skill was so so bad and it will continue to fail me times to times

still not working somehow

local Trap = game.ServerStorage.BearTrap
local Character
local Player 

function plant()
	Character = script.Parent.Parent
	Player = game.Players:GetPlayerFromCharacter(Character)
	
	local PlacedTrap = Trap:Clone()
	local PlacePos = Character.PrimaryPart.Position
	PlacedTrap.Parent = workspace
	PlacedTrap.Position = Vector3.new(PlacePos.x, PlacePos.y-2,PlacePos.z)
end

script.Parent.Activated:connect(plant)

me desperately trying to get this to work properly
i cant point out where is the problem

Did you check the developer console?

It also may be that the Activated event doesnt work since i always tried it and it never worked, ever.

Is it also anchored and cancollide on?

yes it is anchored but no CanCollide
(sorry for late reply i am very busy)

I fixed the problem my self sorry everyone