Client wont receive events from server

I cant get the Server to send a Event trigger to the Client for some reason, i put it into the part i want it to be in, i did everything i could but it didnt work, is there anything i could do to fix it?

Server Script >


–[[ Player along the part. ]]–
local players = game.Players
local part = script.Parent.Position

–[[ Debug to play only once. ]]–
local Stop = false

–[[ Giving maxDistance a value(how close the player has to be before the scipt triggers) ]]–
local maxDistance = 100

–[[ Constantly check to see if the player is close to the part. ]]–
while wait() do
if Stop == false then
for i, player in players:GetChildren() do
if player.Character then
if player:DistanceFromCharacter(part) < maxDistance then
–[[ Debuging ]]–
print(“Player is in border”)

				--[[ We comunicate with the players "view" to Raycast ]]--
				local RayEvent = game.ReplicatedStorage:WaitForChild("RayEvent1")
				
				if RayEvent then
					RayEvent:FireClient(player)
				else
					warn("No RayCast event.")
				end
				
				--[[ Makes the script play only once. ]]--
				Stop = true
				
				--[[ More debuging ]]--
				wait(0)
				
			end
		end
	end
end

end

Client Script >

–[[ Get the Event from ReplicatedStorage. ]]–
local rayEvent = game.ReplicatedStorage:WaitForChild(“RayEvent1”)

–[[-]]–
rayEvent.OnClientEvent:Connect(function()
local partPosition = game.Workspace:WaitForChild(“MonstSpawner”)
local rayOrigin = partPosition + Vector3.new(0, 5, 0)
local direction = Vector3.new(0, -100, 0)

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {script.Parent}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.IgnoreWater = true

local raycastResult = workspace:Raycast(rayOrigin, direction, rayParams)

--[[ Checks to see if the raycastResult exists. ]]--
if raycastResult then
	local resault = {
		raycastResult.Instance,
		raycastResult.Position,
		raycastResult.Material,
		raycastResult.Distance
	}
	
	--[[ Prints the result. ]]--
	print(resault)
	
else
	warn("No raycast result!")
end

end)

Do you get any error in the output?

Your issue lies in player iteration. Replace for i, player in players:GetChildren() do with for _, player in pairs(players:GetPlayers()) do. Also, ensure quotes match (use " or ' consistently) and that Position in script.Parent.Position is a Vector3. Hope this helps :slight_smile:

excuse me i was asleep, could u provide more info on the last part? like the vector3 one

i get none, i only get the server debug, the “Player is in border”, and excuse me i was sleeping

ty dude this helped a lot, the problem for me is that i used a for loop and added the i, which it waited for to be used and thats why i didnt get a signal, then in my local script i didnt specify the location of the MonstSpawner, since i only wrote > local partPosition = game.Workspace:WaitForChild(“MonstSpawner”). thank you so much, this was really helpful, i have been trying for 2 hours. ty once again

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.