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 Localscript (Should be fired Client) The actual script
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
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.
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?
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)
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! )
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
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?