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

Regen vehicle ONLY if not in use?

Asked by 7 years ago

So I'm building a game with usable vehicles (in this case, boats.) and I have a regen button script, but it ONLY regens. I don't want lag to get out of hand, but I also don't want people to get their boats despawned out from under them and leave them stranded.

What I want to do is get a regen made that makes regen'ing the vehicle possible as long as said vehicle is not CURRENTLY being used by someone. (i.e. if someone isn't driving a vehicle, it can be despawned but if they get back into the vehicle once again, you can't regen it until they're out again).

If anymore clarification is needed, please PM me via roblox. Thanks.

Script:

model = script.Parent.Parent--Indicates that the script interacts with the model the button is grouped with.
messageText = ""--If you want a message to appear upon pressing, type it here.

message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true

function regenerate()
    message.Parent = game.Workspace
    model:remove()

    wait(4)--Change this number to display the regen message as long as you want in seconds.

    model = backup:clone()
    model.Parent = game.Workspace
    model:makeJoints()
    message.Parent = nil

    script.Disabled = true
    script.Parent.BrickColor = BrickColor.new(26)--Black
    wait(4)--Change this number to change the time in between regenerations via the button, in seconds..
    script.Parent.BrickColor = BrickColor.new(104)--Purple
    script.Disabled = false
end

function onHit(hit)
    if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
        regenerate()
    end
end

script.Parent.Touched:connect(onHit)

1 answer

Log in to vote
0
Answered by 7 years ago

Why don't use use a BoolValue called Used and when they are siting in the seat it is set to true and if not used is set to false

0
With a few minutes of trying this and doing some tweaking, I got it working (in a way. The Bool itself didn't seem to change, though it's value within the script allowed it to function as meant to, so I suppose that's enough xD). Thanks! SHmods_arebad 0 — 7y
Ad

Answer this question