Light accessory keep falling off player

Hi, devs,

I have some issues (again) but this time it’s a little different. I have been trying to make a light accessory that is given once a player enter a tunnel (by hitting the doorway)

It supposingly stays put on the left side of the player. The light should be shining on the wall. But instead, this happens:

https://i.imgur.com/73dDOVH.mp4
(Don’t mind the poor framerate)

If the video didn’t load, use this: Imgur: The magic of the Internet

This is the code:

local light = game.ServerStorage.light
	
script.Parent.Touched:Connect(function(hit)
	local hasgot = hit.Parent:FindFirstChild("BoolValue")	
	lighting.Atmosphere.Color = Color3.fromRGB(97, 97, 97)
	if hasgot == nil then
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:AddAccessory(light:Clone())
			local got = Instance.new("BoolValue",hit.Parent)
			wait(10)
		end
	end
end)

@WorkPro2007 helped me code this.

Any help please?

Thanks,
Aki

Is the light anchored? That’s the main issue I would expect. (to be clear game.ServerStorage.light)

If I do anchor, the thing would just stay in one place and does not move with the player. I’ll try again just in case.

Oh, you want it to follow the player?
Can’t you lerp or tween it to the player? (or welding, or attachments… etc)

in that case welding is the thing

It does have this but it doesn’t do anything.

image

I tried inserting a weld but it obviously won’t work because I have nothing to attach it to.

Is there another one? Are they connected?
Anyways, I would suggest weld for static following or tween/lerp for dynamic movement

I think if it was dynamic it would be better but I am incapable of doing these things so I might have to stick around with weld or something.

Just Do Weld By Using A Simple Script:

script.Parent.Equipped:Connect(function()
 local weld = instance.new("Weld",script.Parent.Parent.RightHand)
 weld.Part1 = script.Parent.Parent.RightHand
 weld.Part0 = script.Parent
end)

I Am Sure The Light Is A Tool Just Put this script in a script in the tool

Well, try welding first, and if you want to go further on later, play with TweenService.


:thinking:
I may have forgot to mention that it’s an accessory.

It isn’t a tool. It’s an accessory, that’s why it doesn’t work (accessories dont have Equipped)

oh so its not a tool great what type of object is it doe

Oh Yea I thought it was a tool

It’s an accessory… and a part with light inside.

My fault, I forgot to mention that it was.

Just Changed The Equipped To This:

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
 local weld = instance.new("Weld",script.Parent.Parent.RightHand)
 weld.Part1 = script.Parent.Parent.RightHand
 weld.Part0 = script.Parent
end)

Parent The Script To The Accessory

instance.new should be Instance.new

It still didn’t work…

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
	local weld = Instance.new("Weld",script.Parent.Parent.Head)
	weld.Part1 = script.Parent.Parent.Head
	weld.Part0 = script.Parent
end)