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 7 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.

01local tool = script.Parent
02local healValue = 50
03local canHeal = true
04 
05 
06 
07 
08tool.Equipped:connect(function(mouse)
09    mouse.Button1Down:connect(function()
10        local humanoid = tool.Parent.Humanoid
11        if humanoid and canHeal then
12            canHeal = false
13            local currentHealth = humanoid.Health
14            local newHealth = currentHealth + healValue
15            humanoid.Health = newHealth
View all 22 lines...

1 answer

Log in to vote
1
Answered by 7 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:

01local tool = script.Parent
02local healValue = 50
03local canHeal = true
04 
05 
06 
07 
08tool.Activated:connect(function()
09        local humanoid = tool.Parent.Humanoid
10        if humanoid and canHeal then
11            canHeal = false
12            local currentHealth = humanoid.Health
13            local newHealth = currentHealth + healValue
14            humanoid.Health = newHealth
15            wait(2)
16            tool:Destroy()
17        end
18end)
Ad

Answer this question