Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Simple Scripts - Could someone please fix?

enabled = true
function onTouched(hit)
	if not enabled then return end
	enabled = false 
	local h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		h.Sit = true
		wait(0.5)
	enabled = true 
	else
		print"failed"
	end 
end
script.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.

enabled = true
function onTouched(hit)
	if not enabled then return end
	enabled = false 
	local h = hit.Parent:findFirstChild("Humanoid")
	if 	h.Sit == false then
		h.Health = 0
		wait(0.5)
	enabled = true 
		else
		print"failed"
	end
end 
script.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

Hmm, try this;

local debounce=false --Debounce

script.Parent.Touched:connect(function(hit) --The Touched event
if hit.Parent:FindFirstChild("Humanoid")and not hit.Parent.Humanoid.Sit and not debounce then --If finds these things then
debounce=true --Debounce and now true
hit.Parent.Humanoid.Sit=true --Player sits

wait(2) --Waits 2 seconds
debounce=false --Debounce is false again
end
end) --The ends for the code

Hope this helped!

2 comments

0

After playing around with those scripts I finally managed to get them working without a fail, thanks for your time Alpha :)

0

No problem bro. :)

This discussion is preserved as it was. New answers, comments, and votes are closed.