Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

i need someone to explain why this tool relocation isnt working?

Im not the best at making tools and i am making an iron man game with the iconic iron man suitcase but im having issues relocating a model under the handle to workspace Can someone help?



 local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then

	end
		return
	end
	
	local tool = script.Parent

	tool.Equipped:Connect(function()
		tool.Parent = workspace
	workspace.BloxyCola.Handle.Transparency = 1
	workspace.BloxyCola.Handle.Model.Parent = workspace
	wait(3)
	
	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 5) then
			h.Health = h.Health + 5
		else	
			h.Health = h.MaxHealth
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

1 answer

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then

	end
	return
end

local tool = script.Parent

tool.Equipped:Connect(function()
	tool.Parent = game.Workspace -- when addressing "workspace" I would use game.Workspace
	game.Workspace.BloxyCola.Handle.Transparency = 1 -- This isn't really needed
	game.Workspace.BloxyCola.Handle.Model.Parent = game.Workspace -- This is also redundant. 
	-- I took note that you defined the "tool" as the script.Parent
	--This means that this script will always be inside the tool.
	-- So I don't think you need to say game.Workspace.BloxyCola
	-- Do this -- 
	tool.Handle.Transparency = 1
	tool.Model.Parent = game.Workspace
	-- let me know if this works -- 
	
	wait(3)

	local h = Tool.Parent:FindFirstChild("Humanoid")
	if (h ~= nil) then
		if (h.MaxHealth > h.Health + 5) then
			h.Health = h.Health + 5
		else    
			h.Health = h.MaxHealth
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true

end) -- you need a end) to close off your function from line 17. There's a difference between end and end). The main difference is you called upon the function in the same line you made it, so for syntax you need end)

function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Let me know how this goes. I took a quick look at this. Minimal effort went into this fix so I do hope it works.

This discussion is preserved as it was. New answers, comments, and votes are closed.