Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Roblox scripting help
- historical_supa
-
1000+ posts
Roblox scripting help
Dunno if this is supposed to be here, but it probably is.
Anyway, I'm making a Bloxy Cola healing drink thing in Roblox, and I used this old tutorial but I edited the code slightly. Something definitely went wrong. I tried to fix it by using different functions but nothing still works.
local CanActivate = true
local player = game.Players.LocalPlayer
local handle = script.Parent
local sound = handle:WaitForChild('Sound')
function onActivated()
if CanActivate == true then
CanActivate = false
wait(0.5)
player.Character.humanoid.Health = player.Character.humanoid.Health + 15
wait(0.5)
sound
remove this)Play()
wait(7.5)
CanActivate = true
end
end
Could someone help me and make it so that the player heals whenever the item is used? (with the cooldown)
Also, other thing, there are two teams in my game, and every other player they just get into the winners team by joining. This is the code I'm attempting to use to stop that, sorry if I made a dumb silly mistake that's plain to see.
local plr = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
if plr.Team == game:GetService(“Teams”).Winners then
plr.Team = game:GetService(“Teams”).Playing
end
end)
It doesn't work in the workspace nor the severscriptservice thing. How should I fix this?
I'm a beginner to Lua and Roblox coding so please understand if I made obvious mistakes.
Anyway, I'm making a Bloxy Cola healing drink thing in Roblox, and I used this old tutorial but I edited the code slightly. Something definitely went wrong. I tried to fix it by using different functions but nothing still works.
local CanActivate = true
local player = game.Players.LocalPlayer
local handle = script.Parent
local sound = handle:WaitForChild('Sound')
function onActivated()
if CanActivate == true then
CanActivate = false
wait(0.5)
player.Character.humanoid.Health = player.Character.humanoid.Health + 15
wait(0.5)
sound

wait(7.5)
CanActivate = true
end
end
Could someone help me and make it so that the player heals whenever the item is used? (with the cooldown)
Also, other thing, there are two teams in my game, and every other player they just get into the winners team by joining. This is the code I'm attempting to use to stop that, sorry if I made a dumb silly mistake that's plain to see.
local plr = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
if plr.Team == game:GetService(“Teams”).Winners then
plr.Team = game:GetService(“Teams”).Playing
end
end)
It doesn't work in the workspace nor the severscriptservice thing. How should I fix this?
I'm a beginner to Lua and Roblox coding so please understand if I made obvious mistakes.
Last edited by historical_supa (Sept. 8, 2022 08:41:45)
- historical_supa
-
1000+ posts
Roblox scripting help
Yo! Historical's back!It still doesn't work. I've changed nothing but that.
Well, to quote @pkhead:(8)
you should use task.wait instead of wait, as wait is now deprecated.
- pkhead
-
1000+ posts
Roblox scripting help
I think the problem stems from this line:
replace “humanoid” with “Humanoid” (the case of your identifiers matter in programming)
Also, what is
I don’t know if you actually put that in your script
Try replacing that with
Also, using deprecated functions/methods isn’t usually the cause of error, as deprecation just means it’s an outdated practice, and may be removed at any time (although in most cases they don’t to preserve backwards compatibility)
One last thing, it’d be very helpful if you include error messages when you ask for scripting help.
player.Character.humanoid.Health = player.Character.humanoid.Health + 15
Also, what is
sound:(remove this)Play()
Try replacing that with
sound:Play()
Also, using deprecated functions/methods isn’t usually the cause of error, as deprecation just means it’s an outdated practice, and may be removed at any time (although in most cases they don’t to preserve backwards compatibility)
One last thing, it’d be very helpful if you include error messages when you ask for scripting help.
- historical_supa
-
1000+ posts
Roblox scripting help
I tried that. Still didn't work. snip
And yes, I didn't add the remove this thing, it's just to stop the

Also, there were no error messages at all.
- pkhead
-
1000+ posts
Roblox scripting help
did you writeI tried that. Still didn't work. snip
And yes, I didn't add the remove this thing, it's just to stop theemoji from getting in.
Also, there were no error messages at all.
local tool = handle.Parent
tool.Activated:Connect(onActivated)
- historical_supa
-
1000+ posts
Roblox scripting help
Oh, that must be the part wherre I got it wrong. Huge thanksdid you writeI tried that. Still didn't work. snip
And yes, I didn't add the remove this thing, it's just to stop theemoji from getting in.
Also, there were no error messages at all.local tool = handle.Parent
tool.Activated:Connect(onActivated)
edit: ok bruh nvm still doesn't work, don't know where i got it wrong
Last edited by historical_supa (Sept. 10, 2022 05:52:49)
- pkhead
-
1000+ posts
Roblox scripting help
hmmOh, that must be the part wherre I got it wrong. Huge thanksdid you writeI tried that. Still didn't work. snip
And yes, I didn't add the remove this thing, it's just to stop theemoji from getting in.
Also, there were no error messages at all.local tool = handle.Parent
tool.Activated:Connect(onActivated)
edit: ok bruh nvm still doesn't work, don't know where i got it wrong
what type of script is it? is it a local script? because in normal scripts, which run on the server, you cannot access Players.LocalPlayer, as servers do not have a local player.
if it is a server script, instead of using player.Character, you should use tool.Parent, because when equipped, tools get parented to the player's character. if it is a local script, change it to a server script because humanoid.Health needs to be changed on the server.
and for the teams thing, instead of using a script, you can fix it by turning off the “AutoAssignable” property for the Winners team.
Last edited by pkhead (Sept. 10, 2022 15:04:59)
- historical_supa
-
1000+ posts
Roblox scripting help
For whatever reason, I don't know why it still doesn't work. it's a normal script that's a child of the handle, here's the code just in casehmmOh, that must be the part wherre I got it wrong. Huge thanksdid you writeI tried that. Still didn't work. snip
And yes, I didn't add the remove this thing, it's just to stop theemoji from getting in.
Also, there were no error messages at all.local tool = handle.Parent
tool.Activated:Connect(onActivated)
edit: ok bruh nvm still doesn't work, don't know where i got it wrong
what type of script is it? is it a local script? because in normal scripts, which run on the server, you cannot access Players.LocalPlayer, as servers do not have a local player.
if it is a server script, instead of using player.Character, you should use tool.Parent, because when equipped, tools get parented to the player's character. if it is a local script, change it to a server script because humanoid.Health needs to be changed on the server.
and for the teams thing, instead of using a script, you can fix it by turning off the “AutoAssignable” property for the Winners team.
local CanActivate = true
local handle = script.Parent
local tool = handle.Parent
local sound = handle:WaitForChild('Sound')
function onActivation()
if CanActivate == true then
CanActivate = false
task.wait(0.5)
tool.Parent.Humanoid.Health = tool.Parent.Humanoid.Health + 15
task.wait(0.5)
sound

task.wait(7.5)
CanActivate = true
end
end
tool.Activated:Connect(onActivation)
At least the teams were fixed.
- pkhead
-
1000+ posts
Roblox scripting help
if there are no errors, try printing something out whenever the onActivated function runs. this will confirm whether or not the activation is being registered. additionally, print something out when CanActivate is true. (alternatively you could use breakpoints which pause code execution on certain lines, and lets you go through code step by step. to use breakpoints you click on/next to the line number.)
and a child “Sound” does exist in the handle, right? and Handle is a direct child of the tool?
i remember in a game i was making, the activated event wouldn’t register in a tool i was making. eventually i figured out that it was because of a context action binding to the left mouse button in an entirely unrelated script, which would sink the mouse input preventing it from registering the tool activation. if this is the problem in your situation, you can try fixing it by making the context action function return Enum.ContextActionResult.Pass
and a child “Sound” does exist in the handle, right? and Handle is a direct child of the tool?
i remember in a game i was making, the activated event wouldn’t register in a tool i was making. eventually i figured out that it was because of a context action binding to the left mouse button in an entirely unrelated script, which would sink the mouse input preventing it from registering the tool activation. if this is the problem in your situation, you can try fixing it by making the context action function return Enum.ContextActionResult.Pass
Last edited by pkhead (Sept. 14, 2022 12:54:16)
- historical_supa
-
1000+ posts
Roblox scripting help
I used prints but only the first one appears in the output when I click it, which is a bit strange, since the first one is activated after all the local variables are set. There are two others that appear in the onActivation function but when I click it nothing happens. Using the return Enum thing in the code doesn't work either if there are no errors, try printing something out whenever the onActivated function runs. this will confirm whether or not the activation is being registered. additionally, print something out when CanActivate is true. (alternatively you could use breakpoints which pause code execution on certain lines, and lets you go through code step by step. to use breakpoints you click on/next to the line number.)
and a child “Sound” does exist in the handle, right? and Handle is a direct child of the tool?
i remember in a game i was making, the activated event wouldn’t register in a tool i was making. eventually i figured out that it was because of a context action binding to the left mouse button in an entirely unrelated script, which would sink the mouse input preventing it from registering the tool activation. if this is the problem in your situation, you can try fixing it by making the context action function return Enum.ContextActionResult.Pass
- pkhead
-
1000+ posts
Roblox scripting help
I tested your code in Studio and it works exactly as intended. Strange.
I think the only way I could help you further is if you invite me as a team create collaborator to your place, since I'm pretty sure something unrelated is what's causing your code to not function correctly. My username's Bisoph.
I think the only way I could help you further is if you invite me as a team create collaborator to your place, since I'm pretty sure something unrelated is what's causing your code to not function correctly. My username's Bisoph.
- Discussion Forums
- » Things I'm Making and Creating
-
» Roblox scripting help