Hey, devs! It’s a-me, Harmony! So finally, I’m learning to script in Roblox and these are some things that I coded for the first time by myself.
First part changes color and transparency when the player touches the part.
Second part is a Proximity Prompt which again changes color from black to white.
Third & fourth parts are kill and heal parts. (Red part damage’s the player and the Green part Heals the player to full health.
-- Script of the 1st part:
local part = game.Workspace.part
while wait(1) do
part.BrickColor = BrickColor.Black()
part.Transparency = 0.60
part.Transparency = 0
part.BrickColor = BrickColor.White()
-- Script of the 2nd part:
local invpart = game.Workspace.invpart
local invpart = script.Parent
invpart.Transparency = 0
invpart.BrickColor = BrickColor.Black()
-- Script of the 3rd & 4th parts:
-- KILL PART:
local killpart = game.Workspace.killpart
local killpart = script.Parent
local function PlayerTouched(killpart)
local Parent = killpart.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
Parent.Humanoid.Health = 20
local healthpart = game.Workspace.healthpart
local healthpart = script.Parent
local function PlayerTouched(healthpart)
local Parent = healthpart.Parent
Parent.Humanoid.Health = 100
Feedback and suggestions would be appreciated!!
Such a proud feeling isn’t it?
I’m still working on making my own scripts so I don’t know if i should give out any feedback, all I can say is good job and good luck with your scripting journey!
So far, these are the best lines of code I’ve seen from a beginner. Particularly in the case that I haven’t seen any
Plr variables and there’s good indentation and syntax. With a bit more experience using the Roblox API you’ll be a good programmer in no time.
An improvement I’ve noticed you could make is instead of indexing the part directly from the workspace you should use
FindFirstChild if the script is running on the server, or
WaitForChild if the script is not running on the server.
There’s also no real reason to use
game.Workspace. There are several ways you can get the workspace.
workspace -- recommended
-- Script | Serverside Modulescript
-- Localscript | Locally ran Modulescript
Inside of the function
PlayerTouched(healthpart) your parameter has the same name as your variable
healthpart. The actual parameter for that function would be as follows.
PlayerTouched(healthpart) is actually
PlayerTouched(otherPart). I’d recommend using a different variable name in this case instead of a name that’s already in use by a variable.
Why are you using game.Players:GetPlayerFromCharacter in the Heal Part? You don’t set the results to any variable so it doesn’t do anything here. You can check if the part is from a humanoid by doing
With the first KillPart script your use of
game.Players:GetPlayerFromCharacter would make this kill part only work on players and not NPCs. This is useful if you don’t want the part to affect NPCs.
Those are the only things I wanted to point out. Very good job, and I look forward to your future creations.
just wanted to say that the kill part and heal part variables are bad practice
the top two variables are the same thing and have the same name, and the first Touched parameter has the same variable name
also the heal part will error if a
Humanoid doesn’t exist under
you did a check on the kill part, but not the heal part
Yea, like I’m the first ever person to learn and teach Lua in Roblox. Haha
Yes, I know what you’ve mentioned here. But I could not remember it at that time so I typed
game.workspace again and again.
Yes, actually I know that I need to type
otherpart but I thought of typing in my own version to understand better. Thank you for correcting my mistake(s)