#firing events when a part is touched
82 messages · Page 1 of 1 (latest)
Part.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Events.FindExitEvent:FireAllClients()
end
end
do I put this inside a script thats inside the actual part itself?
Altought you would need to add a check to check if its a player. otherwise if anything touches it it will fire the even
Will it depends you can do both
alright
Added some checking to check who touched it has humanoid in it.
You can make it more safer if you REALLY want to make sure its a player touching it
alr
btw, this was my old script (inside a local script)
That works
try debugging it by printing
how do I do that?
like else print ("fail")
?
like this for example
Part.Touched:connect(function(Hit)
print("1")
if Hit.Parent:FindFirstChild("Humanoid") then
print("2")
Events.FindExitEvent:FireAllClients()
end
end
To check at what part it doesnt print
k
okay I thinks its working now
lemme check one more time
ok yes its working!! thanks alot!!
@tribal burrow mark your thread as solved
If you use fireallclients it will fire to everyone on the server
oh its 1 player servers anyway
Oh yeah no problem then
yea
wait
@warm vault
I realised
I can walk over the part and fire it multiple times, how can I make it only work once?
add a debounce
if you want a cooldown
or if you want a toggle, for ever (like one time use) then add a toggle with datastore
yes. how do I do that?
lol I'm relatively new to scripting so sorry for the hassle and stuff
Its okay
local DataStoreService = game:GetService("DataStoreService")
local ExampleToggleName = DataStoreService:GetDataStore("ExampleToggleName") -- Change the name to whatever you want
Part.Touched:Connect(function(Hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") then
local success, toggleValue = pcall(function()
return ExampleToggleName:GetAsync(Player.UserId)
end)
if success and not toggleValue then
ExampleToggleName:SetAsync(Player.UserId, true)
Events.FindExitEvent:FireAllClients()
end
end
end)
and this goes in the same script as the hit function right
yes replace it.
alrighty
There are minor adjustments such as the Part but i think you already know how to fix it?
local Part = script.Parent
but you already know that
yeyye
** You are now Level 5! **
why is there a data store in there
.
uhhh, its still playing multiple times
Right i forgot to set the toggle to true
oh lol
alr i edited it
okey
here
wait
local DataStoreService = game:GetService("DataStoreService")
local ExampleToggleName = DataStoreService:GetDataStore("ExampleToggleName") -- Change the name to whatever you want
Part.Touched:Connect(function(Hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChild("Humanoid") then
local success, toggleValue = pcall(function()
return ExampleToggleName:GetAsync(Player.UserId)
end)
if success and not toggleValue then
ExampleToggleName:SetAsync(Player.UserId, true)
Events.FindExitEvent:FireAllClients()
end
end
end)
here
alr, it works perfect, but in the output its saying "DataStore request was added to the queue. If request queue fills, further requests will be dropped. Try sending fewer requests" is that fine?
For here you could add a debounce letme see what i can figure
bro you don’t need a data store for a debounce lol
Just use a basic debounce
.
i meant a basic debounce
Ye idk why u would have a data store for a debounce at all
i dont?
Unless ur trying to save data unless the player goes offline
He wants it to be a one time use
yea
oh
like you use it once and it never happens again