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

[SOLVED] I'm using a touch event to enable a script but it doesn't work, whats wrong with it?

Asked by 4 years ago
Edited 4 years ago

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

0
Nice screenshots. Especially the last one. 10/10 man. NIMI5Q -2 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
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

0
Thank you mate, it worked! And thanks to everyone else who helped me here. User#22822 0 — 4y
Ad
Log in to vote
0
Answered by
NIMI5Q -2
4 years ago
Edited 4 years ago

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!!!

0
Basically you need to disable it through a script. Preferably the same one as the source code. NIMI5Q -2 — 4y
0
Sorry im quite new to scripting, wat do you mean by this? where do i need to place it? User#22822 0 — 4y
0
Ah, it would go under the same script as you have made. Except! An addition to the very top. NIMI5Q -2 — 4y
0
Well it still doesnt work. I am doing something wrong here but i dont know what User#22822 0 — 4y
View all comments (5 more)
0
Edit your post and link a screenshot of your roblox studio please for further help. NIMI5Q -2 — 4y
0
I have added the screenshots. User#22822 0 — 4y
0
Seems to me a network issue. NIMI5Q -2 — 4y
0
Well, what am i supposed to do? User#22822 0 — 4y
0
your answer doesn't make sense in this case! User#23252 26 — 4y
Log in to vote
-1
Answered by 4 years ago

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
0
Ohhh so the script works fine since the part is touching the baseplate, i hope. Anyways thx for the answer i will test it later. User#22822 0 — 4y
0
Well. It still doens't work, now it doesn't even enable the script and nothing comes out in the output User#22822 0 — 4y
0
this will enable it for everyone and not just one player Gameplayer365247v2 1055 — 4y

Answer this question