Hello!
So this code is intended to create a part which is used as a Powerup for players which will increase their walkspeed and max health by a big amount and it’s only a one time use and I made it so the Powerup can also respawn and I created parts around the Powerup using the code to decorate it I also tried to make it look as good as possible by changing the material, etc…
If you want to test this code in ROBLOX Studio then it’s recommended that you test it in the Baseplate world because that’s where I made this code but you can also just review the code by looking at it and giving me feedback on how to make it better and also if there’s anything to improve on in this code.
Also please tell me if this code is good for a beginner or not and don’t forget to tell me why, this is the first time I create a code like this and also it’s the first time I create a code this big too so I wanted to know what people think, this was very fun to make for me.
Overview:
- This code will create parts including the Powerup part it’s recommended that if you decide to test this code then test it in the Baseplate world because that is where I made all of this code.
- I have tried to improve this code as much as I can but I am new to scripting so I am not sure if this code is perfect.
- I would like to know if there’s anything that I can improve on in this code and if I can make my code look more clean and easy to read by making this code as short as possible.
Code
local part2 = Instance.new("Part")
part2.Anchored = true
part2.BrickColor = BrickColor.new("Sand green")
part2.Position = Vector3.new(-38,0.5,7.5)
part2.Size = Vector3.new(6,1,1)
part2.Material = Enum.Material.Metal
part2.Parent = game.Workspace
local part3 = Instance.new("Part")
part3.Anchored = true
part3.BrickColor = BrickColor.new("Sand green")
part3.Position = Vector3.new(-34.5,0.5,10.5)
part3.Size = Vector3.new(1,1,5)
part3.Material = Enum.Material.Metal
part3.Parent = game.Workspace
local part4 = Instance.new("Part")
part4.Anchored = true
part4.BrickColor = BrickColor.new("Sand green")
part4.Position = Vector3.new(-38,0.5,13.5)
part4.Size = Vector3.new(6,1,1)
part4.Material = Enum.Material.Metal
part4.Parent = game.Workspace
local part5 = Instance.new("Part")
part5.Anchored = true
part5.BrickColor = BrickColor.new("Sand green")
part5.Position = Vector3.new(-41.5,0.5,10.5)
part5.Size = Vector3.new(1,1,5)
part5.Material = Enum.Material.Metal
part5.Parent = game.Workspace
local part6 = Instance.new("Part")
part6.Anchored = true
part6.BrickColor = BrickColor.new("Sand green")
part6.Position = Vector3.new(-38,1,10.5)
part6.Size = Vector3.new(6,2,5)
part6.Material = Enum.Material.Metal
part6.Parent = game.Workspace
function createpart(anchored,transparency,brickcolor)
local part1 = Instance.new("Part")
part1.Name = "Powerup"
part1.Anchored = anchored
part1.Transparency = transparency
part1.BrickColor = brickcolor
part1.Position = Vector3.new(-38,3,10.5)
part1.Parent = game.Workspace
part1.Size = Vector3.new(4,2,3)
part1.Material = Enum.Material.Glass
return part1
end
local returnedpart1 = createpart(true,0,BrickColor.new("Deep orange"))
returnedpart1.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
hit.Parent.Humanoid.WalkSpeed = 30
hit.Parent.Humanoid.MaxHealth = 200
wait(0.2)
hit.Parent.Humanoid.Health = 200
wait(0.3)
returnedpart1:Destroy()
print("Powerup used.")
end
end)
returnedpart1.TouchEnded:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
wait(5)
hit.Parent.Humanoid.WalkSpeed = 16
hit.Parent.Humanoid.MaxHealth = 100
wait(0.2)
hit.Parent.Humanoid.Health = 100
wait(0.1)
print("You lost your Powerup and it cannot be used again.")
wait(10)
local powerupclone = returnedpart1:Clone()
powerupclone.Parent = game.Workspace
wait(0.5)
print("Powerup respawned.")
end
end)