How to fix this script to use abilities properly

I am making it so that an ability can be used to attack enemies in my game, and I am currently using this, but for some reason it says, “Position is not a valid member of MagmaBall” : local event = game.ReplicatedStorage.MagmaAbility . I know this is probably a simple issue, and I am pretty bad at positioning.

event.OnServerEvent:Connect(function(plr)
	local VFX = game.ReplicatedStorage.MagmaBall
	local clonedVFX = VFX:Clone()
	clonedVFX.Parent = workspace
	clonedVFX.Position = plr.Character.HumanoidRootPart.Position
	task.wait(3)
	clonedVFX:Destroy()
end)

The error “Position is not a valid member of MagmaBall” means that whatever you put into VFX (i.e. game.ReplicatedStorage.MagmaBall) is not a BasePart—most likely it’s a Model, a Folder, a instance doesn’t have a .Position property. only BasePart-derived objects have a .Position (and .CFrame). If “MagmaBall” is a Model you have to move one of its BasePart children rather than the Model itself.

edit:

If it’s a model, you can use PivotTo() PVInstance | Documentation - Roblox Creator Hub

1 Like

I did like this and it works (I found it somewhere).:slight_smile:

local event = game.ReplicatedStorage.MagmaAbility

event.OnServerEvent:Connect(function(plr)
	local magmaBall = game.ReplicatedStorage.MagmaBall
	local clonedVFX = magmaBall:Clone()

	-- Set its parent and position
	clonedVFX.Parent = workspace
	clonedVFX:SetPrimaryPartCFrame(plr.Character.HumanoidRootPart.CFrame)

	-- Wait and destroy
	task.wait(3)
	clonedVFX:Destroy()
end)

SetPrimaryPartCFrame is depricated, it still works but PivotTo is the newest version :slight_smile:

1 Like