Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Would I Make This Digging Script Work Properly?

Asked by 5 years ago

Hey guys, I am trying to make a digging game where if you click a diggable part, it will slowly reduce the size of the part until it is completely gone and when it is gone it will give you coins in return. I have a script that works but for some reason when you walk away from the part, you are still able to dig it even when you are not touching it. Anyone know how I am fix this?

Script:

--Script in ServerScriptService

ce.OnServerEvent:Connect(function(plr, part)

part.Size = part.Size - Vector3.new(.01,.01,.01)

end)

--Script in tool

script.Parent.ShovelTip.Touched:Connect(function(hitpart)

mouse.Button1Down:Connect(function()

if hitpart.Name == "Dirt" then

local part = hitpart

harvesting.Value = true

ce:FireServer(part)


end

end)

end)
0
The reason is because you need to use the `` Remove() `` Function. This way it would decrease lag as well because you wouldn't have a million parts in explorer. bestrobloxerall -10 — 5y

1 answer

Log in to vote
0
Answered by
Divistern 127
5 years ago

You have to check for the distance between the LocalPlayer and the current Part To Dig by using Magnitude like in the following.

The script that is going to be used is LocalScript

Getting the Distance between Player and Part. Code: ``` --Variables To be Used-- local part = script.Parent --Getting Part local player = game.Players.LocalPlayer --Getting The LocalPlayer player.CharacterAdded:Wait() --Waiting for the player's Character local char = player.Character --Getting player's Character

spawn(function() --Threading the while loop, so it doesn't crash local TO = char:WaitForChild("Torso") while true do local dist = (TO.Position - part.Position).magnitude if dist <= 6 then --If distance between player and part is 6 studs then print("Player is close and able to dig!") <RemoteEvent>:FireServer() --Firing remote to start digging end wait() end end) ``` And this should be it for checking if player is close or not, this will automaticly dig, you can just modify it a bit.

Hope This Helped.

Ad

Answer this question