✓ Accepted answer
I would check to see if a player is returned by the function GetPlayerFromCharacter before inserting the ParticleEmitters into their hands:
local Part = script.Parent
local function Speed(part)
local parent = part.Parent
if game.Players:GetPlayerFromCharacter(parent) then
local right = Instance.new("ParticleEmitter",parent.RightHand)
local left = Instance.new("ParticleEmitter",parent.LeftHand)
right.Speed = 2
left.Speed = 2
right.RotSpeed = 10000
left.RotSpeed = 10000
right.Texture = ("http://www.roblox.com/asset/?id=3442350629")
left.Texture = ("http://www.roblox.com/asset/?id=3442350629")
right.Rate = 100
left.Rate = 100
right.Rotation = 555
left.Rotation = 555
right.Lifetime = 3
left.Lifetime = 3
end
end
Part.Touched:Connect(Speed)
The reason you should check to see if you're dealing with a player's character first is because it's possible that the part that touched your part is not a member of a player's character model, and then assuming that its parent contains a LeftHand and a RightHand would be unsafe.
Also, using connect is deprecated, meaning it's outdated and has a newer version, and probably won't work in the future. Use Connect instead.
As for your issue with the properties not changing, I would just make the ParticleEmitters in Studio first, put them in your script, and simply clone them and parent them to the character's hands.
local Part = script.Parent
local particleEmitter = script:WaitForChild("ParticleEmitter")
local function Speed(part)
local parent = part.Parent
if game.Players:GetPlayerFromCharacter(parent) then
local clone = particleEmitter:Clone()
clone.Parent = parent.RightHand
local clone2 = clone:Clone()
clone2.Parent = parent.LeftHand
end
end
Part.Touched:Connect(Speed)
And finally, to address your issue with multiple particle emitters being inserted into the player's hands:
local Part = script.Parent
local particleEmitter = script:WaitForChild("ParticleEmitter")
local function Speed(part)
local parent = part.Parent
if game.Players:GetPlayerFromCharacter(parent) then
if not parent.RightHand:FindFirstChild("ParticleEmitter") then
local clone = particleEmitter:Clone()
clone.Parent = parent.RightHand
clone.Enabled = true
end
if not parent.LeftHand:FindFirstChild("ParticleEmitter") then
local clone = particleEmitter:Clone()
clone.Parent = parent.LeftHand
clone.Enabled = true
end
end
end
Part.Touched:Connect(Speed)
Just check to see if a particle emitter is already there.
3 comments
It works but there is a problem. At the origin of the whole game (0,0,0), I see the particle emitter. How do i get rid of it?
I would just disable the particle emitter in Studio and then enable it once you parent it to the hands.
ok. thx