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

FireServer won't fire on client side, but no errors. Why is this happening?

I've put a local script that will fire server into StarterCharacter Scripts, the server side script into ServerScriptService and put the remote event in replicated storage, but client just won't fire server.

Client Side

local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local localPlayers = Players.LocalPlayer
local Mouse = localPlayers:GetMouse()
local StarterGui = game:GetService("StarterGui")
local target
local selected = {}
local moveUnit = ReplicatedStorage:WaitForChild("StartMoveUnit")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

function hit(userInput, cam)
	-- Get mouse position:
	local mousePos = userInput:GetMouseLocation()

	-- Get the ray from the mouse and project it 1000 studs forward:
	local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	mouseRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)

	-- Cast the ray:
	local target, hit = workspace:FindPartOnRay(mouseRay)	
	return hit
end

function isInTable(selected,toFind)
	local found = false
	for i = 1, #selected, 1 do
		if toFind == selected[i] then
			found = true
			break
		end
	end
	return found
end

Mouse.Move:Connect(function()
	if target ~= nil then
		if target:FindFirstChild("IsUnit") and isInTable(selected, target) == false then
			target.Highlight.Transparency = 1
		end
	end
    target = Mouse.Target
	if target and target:FindFirstChild("IsUnit") then
		target.Highlight.Transparency = 0.5		
	end
end)

Mouse.Button1Down:Connect(function()
	local alreadySelected = false
	
	target = Mouse.Target
	
	local i
	
	alreadySelected = isInTable(selected, target)
			
	for i = #selected, 1, -1  do
		selected[i]:WaitForChild("Highlight").Transparency = 1
		table.remove(selected, i)
	end
	if alreadySelected == false then
		if target:FindFirstChild("IsUnit") then
			table.insert(selected, target)
			target.Highlight.Transparency = 0.5
		end
	end
end)

Mouse.Button2Down:Connect(function()
	local location = hit(userInput, workspace.CurrentCamera)
	local willMove
	print(location)
	if selected[1] then
		for i = 1, #selected, 1 do
				willMove = selected[i]
				moveUnit:FireServer(willMove, location)
		end
	end
end)

Server Side

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local moveUnit = ReplicatedStorage:WaitForChild("StartMoveUnit")
local tweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local info = TweenInfo.new(
	2,
	Enum.EasingStyle.Linear,
	-1,
	Enum.EasingDirection.Out,
	0	
	)

moveUnit.OnServerEvent:Connect(function(player,selected, location)
	print("moving")
	local goal = CFrame.new(location)
	local Tween = TweenService:Create(selected,info,goal)

	Tween:Play()
	wait(2)
	Tween:Stop()	
end)

3 comments

0

Use the print() command under every line that runs and see when the prints stop, that's where the error is... if all of them run then you have everything correct in theory but something is referenced wrong.

0

I put print() command after it firesserver in the for loop, before fire server in the for loop, in the server side connect script, but they all print out except server side. Server side never connects.

1

Um you sure you aren't firing the wrong event? Or receiving the wrong event on server side?

1 answer

So what i've been able to gather from your comments is that you are most likely firing the wrong event. I would check into it. Go through the local script that fires the Server Side, until the Client side script fires the server side, it won't work. If it's not that, see if you have the same things in the function() side of the fire. Make sure it's reading correctly. It's not firing the server side script so it's the client side script that's got an error. I see nothing wrong with the scripts so I would highly look into which event is firing and so on.

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