RemoteEvent ontouch won't be fired in client

Dear DevForum,

I have a script that should print something out for the localplayer when the ontouch brick gets touched but sadly it does not do that. I have uploaded two scripts within this topic (Client and the ontouch script of the brick that gets touched) and if you need more info i gladly give that if needed.

Thank you for reading this post i appricate your help!

Ontouch brick

local Path = script.Parent
local Model = Path.Parent
local debounce = false
local MarketShopController = Path.ScreenGuiFolder.MarketShopController
local NPC = Model.Clappy
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventFolder = ReplicatedStorage.RemoteEventMarket


local function OnTouchShop (PartThatGotTouched)
	local player = game.Players:GetPlayerFromCharacter(PartThatGotTouched.Parent)	
	local character = PartThatGotTouched.Parent
	if debounce == false and player and player.PlayerGui:FindFirstChild(MarketShopController.Name)==nil then
		debounce = true
		print(player.Name,"Touched the brick")
		character.DisablePlayerControls.Disabled = false
		MarketShopController:Clone().Parent=player.PlayerGui
		print(player.Name,"Got the GUI")
		RemoteEventFolder.GreetingEmote:FireClient(player)
		wait(1)
		debounce = false
	end
end

Path.Touched:Connect(OnTouchShop)

RemoteEvent (LocalScript that should be fired in the output of the localplayer)

script.Parent.OnClientEvent:connect(function(player)

print(player.Name,"Fired a ClientEvent!")

end)

Screenshots that may help solving it (or directions where everything is):
The path that activate the script
image
Localscript (Should be fired Client)
image
The actual script
image

When you did local function onShop () I think it should be local function onShop()

The function works fine but the only problem is that the event won’t be seen (aka it won’t be printed in the output) the rest of all other things it should do just works

Is it in the server? client to server?

Print something at the top of the .Touched function. If nothing comes it up it’s not getting fired somehow. Maybe the part is too small.
Also, make sure to look for a humanoid before getting the character and the player. Another part could touch it, which isn’t a player but you’re still acting as if it is a player.

Another thing, correct me if I’m wrong but local scripts don’t work in ReplicatedStorage unless you’re cloning the remote event to somewhere. Try putting the local script in StarterGui.

Try placing the Local Script elsewhere. (If your using FE (Filtering Enabled) )
https://developer.roblox.com/en-us/api-reference/class/LocalScript

I though that if you get the GetPlayerFromCharacter you already know it’s a player as it looks into the players for the player that touched the part?

and would the RemoteEvent work if i did place it in workspace?

image
Both ontouch prints work expect the local one from the replicatedstorage (check screenshots above for more info) and thank you for your reply!

I’m not sure if a RemoteEvent would work in workspace, the best place to put them is in ReplicatedStorage. The local script was located inside of the remote event, and local scripts don’t run if it’s a descendant of ReplicateStorage.

Ahhh, that may explain some things indeed. May i ask which location you recommend then as i want to fire a client event to greet the person if he stands on the path after the print works? (an animation)

Well like i said to fastkingyaya, what is the best you suggest then to solve this issue as i want to run a animation for the player locally after the print? (And also thank you for helping)

Well I recommend putting them into ServerStorage and cloning it to PlayerScripts when needed in replacement of firing the server.

If you want to destroy it afterward you may do so with the ServerScript by;

  1. Listening out for an OnServerEvent
  2. Waiting for things that stop at the end of the animation.

It’s really your decision.

I’m a bit confused here how this should be scripted, as you’re telling me that the localscript should be copied over from serverstorage > playerscripts (with fireclient) and then it get automatically trigged or? (and thank you for helping me out! :slight_smile:)

local function OnTouchShop (PartThatGotTouched)
	local player = game.Players:GetPlayerFromCharacter(PartThatGotTouched.Parent)	
	local character = PartThatGotTouched.Parent
	if debounce == false and player and player.PlayerGui:FindFirstChild(MarketShopController.Name)==nil then
		debounce = true
		print(player.Name,"Touched the brick")
		character.DisablePlayerControls.Disabled = false
		MarketShopController:Clone().Parent=player.PlayerGui
		print(player.Name,"Got the GUI")

		local scriptClone = game.ServerStorage.LocalScript:Clone() -- Replaced the RemoteEvent.
		scriptClone.Parent = player.Backpack -- Changed from PlayerScripts

		wait(1)
		debounce = false
	end
end

Or something like that.
(No problem :slight_smile: )

Shouldn’t be in playerscripts?
image

1 Like

Yea sorry I forgot… Ill edit it now.

Actually when i change it to playerscripts it comes up with the following error:
image
Which is strange as it is a valid member of the player?

Does this error occur as soon as the player spawns or after touching the part?

If after touching the part… I’m not sure you can potentially replicate it to backpack instead

If before touching the part… you may need to add a wait so the player has time to load in. It normally takes about 5-8 seconds for a player to fully load in the game.

It happend after touching the part and everything else does work as you can see above. I shall try the backpack one and asap give you answer about this.

Backpack seems to work but the script does not work now (as it is not a fireclient anymore) any tips on detecting localplayer when it is not yet in the player as i believe it was something with WaitForChild?