Hey, so I’m just trying to connect a function when this script’s parent (Tool) is cloned and given to a player but it doesn’t seem to work.
My Code:
local Tool = script.Parent
Tool.Parent.Changed:Connect(function()
-- Code Stuff
end)
Hierarchy:
All I’m doing is cloning the Tool (located in ServerScriptService) and changing its parent, yet the Parent.Changed doesn’t fires. Your help is appreciated!
Still nothing. Maybe there’s another way I could detect when the tool is given to a Player? I mean I know I could use some events but I would’ve thought there was a simpler way to do it.
There is some strange functionality with part.changed and part parent detection. I was testing in studio aswell. Try this, if this doesn’t work than tell me the use of the parent detections and what you need it for and we can work out a different strat.
local Tool = script.Parent
local prevParent = Tool.Parent
Tool.Changed:Connect(function()
if Tool.Parent ~= prevParent then
prevParent = Tool.Parent
print("put code here for parent chage.")
end
end)
Hmm, doing some testing right now and I noticed something. When it’s cloned, it doesn’t run the script until after the parent’s already changed. Meaning it doesn’t run until the player gets it.
Heres the clone script,
local cd = script.Parent.ClickDetector
local gun = game.ServerScriptService.AT_ScriptService.WeaponStorage["M16_Rifle"]
cd.MouseClick:Connect(function(Plr)
local c = gun:Clone()
c.Parent = Plr.Character
end)
Already tried that, it doesn’t do anything. I’m starting to think that Studio might be having an issue right now, everytime I click Play I spawn in as a “Noob” character. What strikes me as even more weird is that the Event.Fire() that I set off in the Parent.Changed Code block, fired the event but it didn’t print the line above it…