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

Simple Scripts - Could someone please fix?

Asked by 10 years ago
01enabled = true
02function onTouched(hit)
03    if not enabled then return end
04    enabled = false
05    local h = hit.Parent:findFirstChild("Humanoid")
06    if (h ~= nil) then
07        h.Sit = true
08        wait(0.5)
09    enabled = true
10    else
11        print"failed"
12    end
13end
14script.Parent.Touched:connect(onTouched)

I wanted the first script to sit a person when they touch it, and if anything other than a humanoid touches it, it will only print and not run the function. So let's say a player drops a hat onto the brick, the script will then break - but I have no idea how to do that :/ -- There might be a problem with my debouncing and use of else with it.

01enabled = true
02function onTouched(hit)
03    if not enabled then return end
04    enabled = false
05    local h = hit.Parent:findFirstChild("Humanoid")
06    if  h.Sit == false then
07        h.Health = 0
08        wait(0.5)
09    enabled = true
10        else
11        print"failed"
12    end
13end
14script.Parent.Touched:connect(onTouched)

The second script is meant to kill any player touching it if they're not sitted. So if anything other than a humanoid, or a dead humanoid touches it, it will not break and only print. -- There might be a problem with my debouncing and use of else with it.

Could someone fix both for me? I'm not a great scripter and can't seem to figure out the problem with these scripts :/

1 answer

Log in to vote
0
Answered by 10 years ago

Hmm, try this;

01local debounce=false --Debounce
02 
03script.Parent.Touched:connect(function(hit) --The Touched event
04if hit.Parent:FindFirstChild("Humanoid")and not hit.Parent.Humanoid.Sit and not debounce then --If finds these things then
05debounce=true --Debounce and now true
06hit.Parent.Humanoid.Sit=true --Player sits
07 
08wait(2) --Waits 2 seconds
09debounce=false --Debounce is false again
10end
11end) --The ends for the code

Hope this helped!

0
After playing around with those scripts I finally managed to get them working without a fail, thanks for your time Alpha :) excellentAnarchy 50 — 10y
0
No problem bro. :) TheeDeathCaster 2368 — 10y
Ad

Answer this question