I want a remote event to fire when a player touches an object but it does not fire and I am getting no errors.
-- Local script local ReplicatedStorage = game:GetService("ReplicatedStorage") local OpenShopGuiEvent = ReplicatedStorage:WaitForChild("OpenShopGuiEvent") local Players = game:GetService("Players") local player = Players.LocalPlayer local playerGui = player:WaitForChold("PlayerGui") local function onOpenShopGuiFired(player) print(player.Name.." opened the shop") if playerGui.AdvancedShopGUi.MainShopFrame.Visible~=true then playerGui.AdvancedShopGUi.MainShopFrame.Visible = true end end OpenShopGuiEvent.OnClientEvent:Connect(onOpenShopGuiFired) -- Server script local ReplicatedStorage = game:GetService("ReplicatedStorage") local OpenShopGuiEvent = ReplicatedStorage:WaitForChild("OpenShopGuiEvent") m = require(game:GetService("ServerScriptService").MainModule) function touch(hit) print("Touched") OpenShopGuiEvent:FireClient(game.Players[m.PlayerName]) end script.Parent.Touched:Connect(touch)
Often times, beginning users will assume that LocalScripts can go anywhere. They would think that since it will allow them to use LocalPlayer, then why not just stick them in a brick in the workspace. Well, sad to say that it can not be done like this.
LocalScripts can only be used in PlayerGui, Backpack, PlayerScripts. ReplicatedFirst, or the Player's Character.
In addition to the locations of LocalScripts, many early script writers will assume that since a script works in Studio Mode it will work in Roblox Server mode.
In Roblox Studio Play Solo mode, which is what many people test with, the game does not tell the difference between server and client. They are both one in the Play Solo mode. That is why a LocalScript may have access to ServerScriptService or ServerStorage.
However, in Roblox Server mode you have to take into account the separation between the server and the client. A client will run LocalScripts which will allow the script access to LocalPlayer and CurrentCamera. If you have FilteringEnabled enabled then this separation becomes all the more apparent. You would need to use a LocalScript for modifying Guis that originate from StarterGui, and ServerScripts for modifying Workspace objects or other Player Damage.