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

Remote Event is not firing when I player touches an object?

Asked by
tjtorin 172
5 years ago
Edited 5 years ago

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)
0
You’re calling FireClient on the client, will error. User#19524 175 — 5y
0
What do you mean? @incapaz tjtorin 172 — 5y
0
"game.StarterGui.AdvancedShopGUi.Parent = playerGui" is redundant, as all objects within the StarterGui are automatically replicated to the PlayerGui. T0XN 276 — 5y
0
Incapaz, I was confused as well because he's put both scripts in one code block, but he's used comments to separate them instead. T0XN 276 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

LocalScripts Not Running

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.

Source

Ad

Answer this question