Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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)
Ad

Answer this question