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

Help Firing from Server to Client?

I'm trying to code a simple outline for a block that infects you with a virus, and I'm trying to send the server script to a LocalScript for easier changing of player values, etc.

My current script (which is inside of the part that you need to walk on) is this:

--Variables

local Players = game:GetService("Players")
local pressed = false

--Script

script.Parent.Touched:Connect(function(hit) 
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		if not pressed then
			
			pressed = true
			
			local chance = math.random(1,10) 
			local incubation = math.random(60, 120)
			
			print("FVZ-112 Script Fired.")
		
			local event = Instance.new("RemoteEvent")
			event.Parent = game.ReplicatedStorage.Viruses.FVZ112
			event.Name = "onTouched"
		
			print("Event Defined.")
		
			local function onTouched(player)
				event:FireClient(player)
			end
		
			script.Parent.Touched:Connect(onTouched)
		
			print("Event Fired")
			wait(5)
			pressed = false
			
		end
	end	
end)


The problem is that when I step on the button, in the output it says "FireClient: player argument must be a Player object"

I know that the incubation and chance values aren't doing anything currently, but I'll implement them once I've made sure the script works.

1 comment

0

try changing the remote event name, the name of an object can interfere with the script. such as naming an object Color.

1 answer

✓ Accepted answer

The BasePart.Touched event has a special argument that returns the part that touched

Here is a simple script getting the player

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		print(player.Name) -- Prints the players name, so it would print "BashGuy10"
	end
end)

So, in your case it would be:

--Variables

local Players = game:GetService("Players")
local pressed = false

--Script

script.Parent.Touched:Connect(function(hit) 

	if hit.Parent:FindFirstChild("Humanoid") then
	
		if not pressed then
		
			 pressed = true
			
			local chance = math.random(1,10) 
			local incubation = math.random(60, 120)
			
			print("FVZ-112 Script Fired.")
			
			local event = Instance.new("RemoteEvent")
			event.Parent = game.ReplicatedStorage.Viruses.FVZ112
			event.Name = "onTouched"
			
			print("Event Defined.")
			
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			event:FireClient(plr)

			print("Event Fired")
			wait(5)
			pressed = false
			
		end
	end 
end)


OH LOOK ITS A FREE WIKI LINK

1 comment

0

Mark this as the answer if it helped!

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