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

Very Weird Problem With My Script, The Tool Will Work In Studio, But Not In Game?

Alright I made a MedKit. Strange thing is, it works when I test it in ROBLOX Studio, but when I play the actual game, the medkit does not work. It is composed of a Tool named Medical Kit, a Union inside named Handle, and a Script named MedKitScript. It is a normal script.

local tool = script.Parent
local healValue = 50
local canHeal = true




tool.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(function()
		local humanoid = tool.Parent.Humanoid
		if humanoid and canHeal then 
			canHeal = false
			local currentHealth = humanoid.Health
			local newHealth = currentHealth + healValue
			humanoid.Health = newHealth
			wait(2)
			tool:Destroy()
		end
		
	
	end)
end)

1 answer

✓ Accepted answer

The mouse can only be accessed from the client I think. My guess to solving this problem is instead using tool.Activated, in which it fires every time the players activates the tool:

local tool = script.Parent
local healValue = 50
local canHeal = true




tool.Activated:connect(function()
        local humanoid = tool.Parent.Humanoid
        if humanoid and canHeal then 
            canHeal = false
            local currentHealth = humanoid.Health
            local newHealth = currentHealth + healValue
            humanoid.Health = newHealth
            wait(2)
            tool:Destroy()
        end
end)

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