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

For some reason, the parts of the code that are not suppose to come first come first?

So for some reason, the code is suppose to go back and forth between the server,which it does, however it does it in the wrong order. I have checked the code using print to debug and it goes Test, Tested, Testing, instead of Testing, Tested, Test.

That is the only problem with the script. Help.

local script:

local Yes
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")
local Object = ReplicatedStorage:WaitForChild("Flowers")

Playerer = game.Players.LocalPlayer
Mouse = Playerer:GetMouse()

Mouse.Button1Down:Connect(function()
	RemoteFunction:InvokeServer(Object)
	print("Testing")
end)

RemoteFunction.OnClientInvoke = function(player)
	
local Flowers = game.Workspace:FindFirstChild("Flowers")
	Yes = Playerer.Character:FindFirstChild("Torso") or Playerer.Character:FindFirstChild("UpperTorso")
	Flowers.Parent = workspace
	Flowers:SetPrimaryPartCFrame(CFrame.new(Yes.Position + (Yes.CFrame.lookVector * 2.5)))
	
	print("Test")
end

script:

local Flowers = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")
Object = game:GetService("ReplicatedStorage"):WaitForChild("Flowers")


RemoteFunction.OnServerInvoke = function(player, Object)
	Flowers = Object:Clone()
	Flowers.Parent = workspace
	RemoteFunction:InvokeClient(player)
print("Tested")
	end

1 answer

✓ Accepted answer

The invokeClient function does not waits the listened functions to execute. Actually all it does is fire a message "in the air" and print "tested". While the "Tested" is being printed, the listened functions are executing their first line. Got it?

Also, if the functions won't return anything, it is better for you to use remote events instead of remote functions. Remote functions are used when you need to return a value and you are waiting for this value when you call the function. So usually a variable is set to the remote function, like this:

Variable = RemoteFunction:InvokeClient(player, parameters)
--or
Variable = RemoteFunction:InvokeServer(parameters)

if variable == true then
	-- do stuff
end

Functions can return values if you tipe "return" and something. Like:

function doStuff()
	local blue = BrickColor.new("Bright blue")
	return blue
end

This way, a returned value would be the one stored in "Variable" in the script above.

1 comment

0

When I read this, I did not understand, now I do. I am really new to servers and clients working together. I solved the problem on my own. Thank you for your solution, take a upvote :D

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