So, I've been having problems getting an onTouch script to work in a server. In test mode it works fine, but on an actual server it fails to work. At first I thought it was the value that wasn't responding, but then I added a print to the script to make sure that the onTouch was actually firing, and, to my surprise, it was actually the script itself that was failing to fire when the brick was touched. Here's the script:
function onTouch(t) print("is this working?") game.Players.LocalPlayer.PlayerGui.HUD.TextT.Trigger.Value = "enemy" end script.Parent.Touched:connect(onTouch)
It's a very simple script, which confuses me as to why it isn't working. All help is appreciated.
Nice attempt. For TouchedEvents, they need to be server-sided scripts (A normal script), usually located inside the part that's touched. Since it's server-sided, you can't use LocalPlayer. Now, you may be wondering, how do I get the player? Well, you can use the :GetPlayerFromCharacter() Method! Here's your code fixed up:
script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then -- Checks if it's a player local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.PlayerGui.HUD.TextT.Trigger.Value = "enemy" -- If the game is FilteringEnabled, you'll need to use RemoteEvents for this line end end)
Hope I helped! If you have any questions, feel free to comment!