Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Code works in a server script but doesn't work on a local script?

Hello, I am currently trying to get some code to work client-sided. However, nothing happens in a local script and I'm not sure why.

My code:


local eggs = game.ReplicatedStorage.Eggs

local spawns = game.Workspace.EggSpawns
	
	local spawn = spawns.EoTS
	
	local eots = eggs["Egg of True Skill"]
	
	local eggClone = eots:Clone()
	eggClone.Parent = game.Workspace.SpawnedEggs
	
	eggClone.Position = spawn.Position + Vector3.new(0,0.5,0)
	eggClone.Anchored = false

	eggClone.Touched:Connect(function(hit)
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if plr then
			game.ReplicatedStorage.FoundEgg:FireClient(plr,eggClone.Name)
			eggClone:destroy()
			
		
		end
	
	
	end)

4 comments

0

You can't use local script for touch event

0

yes you can.

3

From what I know you can't FireClient from local script, only FireServer

1 answer

✓ Accepted answer

The issue lies on line 19. You're trying to use FireClient from a localscript. A client cannot directly communicate with another client. What you would have to do instead, is to send your data to the sever and let the server forward it to its destination.

This discussion is preserved as it was. New answers, comments, and votes are closed.