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

How would i fix my remotefunction that doesnt return anything?

so i have a remotefunction supposed to return the hit of a mouse of a person but it just doesnt let the script past

Script firing the remotefunction

local lastoccupant
local dmg = 15
local turret = script.Parent.turret.Value
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	if script.Parent.Occupant then
		lastoccupant = script.Parent.Occupant
		local newtool = game.Lighting["Mounted .50 Machinegun"]:Clone()
		newtool.Parent = game.Players:GetPlayerFromCharacter(lastoccupant.Parent).Backpack
		lastoccupant:EquipTool(newtool)
		newtool.Activated:Connect(function(mouse)
			newtool.Activated:Connect(function()
				print("activated")
				local ahit = workspace.MouseHit:InvokeClient(game.Players:GetPlayerFromCharacter(lastoccupant.Parent))
				print(tostring(ahit))
		workspace.TurretFire.ServerToServer:FireClient(game.Players:GetPlayerFromCharacter(lastoccupant.Parent),ahit,turret.Barrel,dmg,true)
	end)
		end)
	end
end)

the remotefunction

script.Parent.OnClientInvoke:Connect(function()
	print("returning hit")
	return game.Players.LocalPlayer:GetMouse().Hit.p
end)

ServerToServer remoteevent

script.Parent.OnClientEvent:Connect(function(hit,barrel,dmg,turn)
	print("server to server called")
	script.Parent.Parent:FireServer(hit,barrel,dmg,turn) --fires the TurretFire remote
end)

TurretFire remoteevent


script.Parent.OnServerEvent:Connect(function(player,hit,barrel,dmg,turn)
	local ray = Ray.new(barrel.Position, (hit - barrel.Position).unit * 300)
	if turn then
		barrel.Parent.CFrame = CFrame.new(barrel.Parent.Position,hit)
	end
	print("shooting")
	local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
	if part then
		local hpthing = part:FindFirstChild("hp")
		if hpthing then
			hpthing.Value = math.clamp(hpthing.Value - dmg,0,100)
			if hpthing.Value == 0 then do
				local newpart = part:Clone()
								part.Transparency = 1
				part.CanCollide = false
				newpart.CFrame = part.CFrame
				local newparts = newpart:GetChildren()
				for i=1,#newparts do
					local thang = newparts[i]
					if thang:IsA("Weld")or thang:IsA("LocalScript")or thang:IsA("Script")or thang:IsA("WeldConstraint") then
						thang:Destroy()
						
					end
				end
			end end
		end
	end
--yes i gave up at this point
	local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.new("New Yeller")
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		
		local distance = (barrel.CFrame.p - position).magnitude
		beam.Size = Vector3.new(0.2, 0.2, distance)
		beam.CFrame = CFrame.new(barrel.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		
		game:GetService("Debris"):AddItem(beam, 0.1)	
end)

2 answers

For RemoteFunctions, you don't use :Connect(function(), you use = function()

So, Line 1 on the RemoteFunction script should be

script.Parent.OnClientInvoke = function(arguments)

RemoteFunction Wiki

RemoteFunctions are different from RemoteEvents. RemoteEvents use :Connect(function(args), but RemotFunctions use = function(args).

Hope this helped!

1 comment

0

didnt work

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