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

when player touches block, event occurs for all players?

hi, i am making a game and when the player touches the indicator, I want it to broadcast an event for that player, but when a player touches it, all players in the server receive the event.

local myPart = game.Workspace.indicator1
local otherPart = myPart.Touched:Wait()
print("Part was touched by: " .. otherPart.Name)
script.Parent.Parent.Parent.Enabled=true

here is my code in the local script. indicator1 is what is touched to broadcast the event. would i change this to an "if" statement? thank you!

2 comments

0

^^ also I am new to coding, so I apologize if this is an obvious question.

0

replied to your comment. please accept <3

1 answer

do:

game.Players:FindFirstChild(otherPart.Name).PlayerGui.ScreenGui.Enabled = true

Reasoning: script.Parent.Parent.Parent.Enabled=true would make it appear for all players because it will make it enabled on the starter gui, not playergui

If you want more info click on this link.

8 comments

0

thanks so much for your help! i understand what I did wrong! just wondering so i can get this to work before accepting an answer, do I replace the final line with the one you've given? it didn't seem to do anything unless i messed up somewhere. thank you so much

0

yes, replace rge line with the one i gave

0

the

0

does it work while testing in studio or should I be in the actual game? right now it isn't working while in studio and i was wondering if I needed to go into the actual game.

0

hm, make sure the gui name is screengui and its inside startergui

0

Are you sure this would work? If a part was unanchored and touched the object it would still broadcast the event.

0

not sure, it sshould be achored though

0

okay I found out the problem, I keep getting the error attempt to index nil with playergui so I tried changing it to a normal script but I’m getting the same error. I’m trying to figure it out right now but I’m still not sure what to do! thank you

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