So i made a part, inserted a script inside then made it use touch events. And i wanted it to enable a script when the player touches it and it works but without actually touching it. I mean as soon as you run the game it just enables the script and that's it. It does nothing if you walk over the part, How do i fix this? this is the script:
function OnTouch(hit)
game.StarterGui.ScreenGui.Frame.LocalScript.Disabled = false
end
script.Parent.Touched:Connect(OnTouch)
https://imgur.com/a/APIK20L
https://imgur.com/a/dlYWeOl
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.PlayerGui.ScreenGui.Frame.LocalScript.Disabled = false end end)
this will get the player that touched the part and enable its local script
Sorry but it seems like you've ran into a problem there! Do this?
-------------------------------------- -- BTW IT IS A NETWORK ISSUE ------------------------------------------ script.Disabled = true script.Parent.Touched:Wait()... --[[ Hello, in this comment I will discuss, the Touched event. It is an event that fires when the specified 'thing' touches anything else unless explicitly told in the source code. The source code is where all the logic is contained. Your code is fine. You just need to read this: --]]
Here It's okay if you don't understand it. Just get a rough idea. Thank You!!!
well; keep in mind that anything that touches the part will cause the Touched()
event to fire,
therefore, you should check to see whether the the touching part is a part of the player's character; and here is how you can do it..
function onTouch(part) local parent = part.Parent local players = game.Players if parent:FindFirstChild("Humanoid") and players:FindFirstChild(parent.Name) then game.StarterGui.ScreenGui.Frame.LocalScript.Disabled = false end end script.Parent.Touched:Connect(OnTouch);
so the above code checks whether the parent of the touching part has a humanoid
, and whether it has an associated player object; if so then it has ensured that the touching part is a limb of a player; remember that, the function provided to the Touched()
event with Connect()
is called with the touching part, this way so you know which part is touching;
for example: if i have a part and that part is touched by another part named "touching", then if i did the following it should print "touching" in output
function onTouch(touching) print(touching.Name) -- will print "touching" in output end