#help with changing one objects int value (hits required to chop)
1 messages · Page 1 of 1 (latest)
the "hithandler" script
script.Parent.Hit.OnServerEvent:Connect(function()
if script.Parent.Hits.Value == 1 then
script.Parent.Dead.Value = true
if script.Parent.Trunk:FindFirstChild("HealthGui") then
local ui = script.Parent.Trunk:FindFirstChild("HealthGui")
ui.WhiteBar:Destroy()
end
for i,v in script.Parent:GetChildren() do
if v.Name == "Leaves" then
v:Destroy()
end
end
if script.Parent.Trunk:FindFirstChild("ProximityPrompt") then
script.Parent.Trunk.ProximityPrompt.Enabled = true
script.Parent.Trunk.Anchored = false
end
else
script.Parent.Hits.Value -= 1
if script.Parent.Trunk:FindFirstChild("HealthGui") then
local ui = script.Parent.Trunk:FindFirstChild("HealthGui")
ui.WhiteBar.Size = UDim2.new(script.Parent.Hits.Value/initialHits, 0, 0.2, 0)
end
end
end)```
the actual swing handler in the axe itself
script.Parent.Activated:Connect(function()
if deb == false then
deb = true
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
if mouse.Target.Name == "Trunk" then
local Distance = (mouse.Target.Position - player.Character.HumanoidRootPart.Position).Magnitude
if Distance <= 10 then
if mouse.Target.Parent:FindFirstChild("Dead") then
if mouse.Target.Parent:FindFirstChild("Dead").Value == true then
else
if mouse.Target.Parent:FindFirstChild("Hit") then
mouse.Target.Parent:FindFirstChild("Hit"):FireServer()
end
end
end
end
end
wait(.8)
deb = false
end
end)```
the problem comes from that the actual "hits" isnt inside the axe its inside the tree
damn
I dont have yet solution to your problem, but I can see that your code will be very hard to maintain and it uses wait instead of task.wait
you should organize it more
also nesting gives its effect too
i used a youtube video for it and the person didnt really explain it alot, i thought i could learn from the script itself but it all seems very vague.
i hoped to build up from it but as u can see its not going well
I mean probably video was atleast 3-4 years old
Because wait is already red flag
Like I can see how logic works
Its alright I guess, I mean for youtube video its logic if it works it works
But lioe for learning thats awful
Like
So you want like to add multiplier to hitting trees or what?
I didnt understand goal really
i want it so you can upgrade your axe after getting lets say 5 wood so it takes like 10 hits or a multi like you say
not my code
Like in your current structure I need to think a bit how to not make it worse
Because its already so bad
try to learn how to make it
I know that judging in terms of pro coding this is awful, but if you are beginner thats alright
i dont wanna have to ask if you could like go into the actual studio project and understand the other scripts and whatnot but i dont wanna waste ur time
because theres other code not mentioned too and its all just
Like considering quality of code
I suggest you to remake it yourself
Without trying to use tutorial, like use own logic
Even if it would be awful, just try using recent knowledge
Because clearly this 4 years old tutorial is so bad currently
It teaches you awful approaches like nesting, using deprecated methods
lack of local variables
violating single responsibility
ill try and explain what i know
script.Parent.Hit.OnServerEvent:Connect(function() /// dont really understand
if script.Parent.Hits.Value == 1 then
script.Parent.Dead.Value = true
if script.Parent.Trunk:FindFirstChild("HealthGui") then
local ui = script.Parent.Trunk:FindFirstChild("HealthGui")
ui.WhiteBar:Destroy()
end
for i,v in script.Parent:GetChildren() do
if v.Name == "Leaves" then
v:Destroy() /// gets rid of the leaves on the tree
end
end
if script.Parent.Trunk:FindFirstChild("ProximityPrompt") then /// finds prox prompt
script.Parent.Trunk.ProximityPrompt.Enabled = true /// turns on prox prompt
script.Parent.Trunk.Anchored = false /// unanchors tree trunk
end
else
script.Parent.Hits.Value -= 1
if script.Parent.Trunk:FindFirstChild("HealthGui") then
local ui = script.Parent.Trunk:FindFirstChild("HealthGui")
ui.WhiteBar.Size = UDim2.new(script.Parent.Hits.Value/initialHits, 0, 0.2, 0) /// divides the white bar evenly so its smooth no matter the hit value.
end
end
end)```
Look
Like I can understand you are at tutorial stage and currently dont understand at all how to maintain scripts
Learn more about stuff you dont understand
Like this first commented line
script.Hit.OnServerEvent
like thats remote event connected function
once remote fires it calls function which is this
like your tool activates and it fires event
Learn about that
Just dont get stuck on things like that lol
whats the dev thing called where it gives guides on scripting
nvm its documentation
BrawlDev better
i wanna enjoy coding but it feels like im just always gonna be stuck at like the bottom