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

How can i send arguments from Client to Server?

I'm still trying to figure out FireClient so imma need some help here. I have this script where when a player joins it copy's something in replicated Storage. Once it copies it It sends a Remote Event to the server which tells it to loop its BodyPosition to The Players Torso. But The arguments for some reason won't work. Here are my errors are

20:10:39.390 - Player is not a valid member of DataModel

Local Script


game.ReplicatedStorage.DoDun.OnClientEvent:Connect(function(Player,Part)
	local bp = Instance.new("BodyPosition")
	bp.Parent = Part
	bp.P = 20000		local Part = game.ReplicatedStorage["Creation Replicator"]:Clone()
		Part.Parent = workspace
	bp.Position = game.Player.Character.Torso.CFrame * CFrame.new(-2,0,0).Position
	wait()
	bp:Destroy()
end)

Server Script

game.Players.PlayerAdded:Connect(function(Player)
		local Part = game.ReplicatedStorage["Creation Replicator"]:Clone()
		Part.Parent = workspace
while true do
	wait()			
	game.ReplicatedStorage.DoDun:FireClient(Part)
end
end)

5 comments

0

You didn't specify which player's client to fire, you did "FireClient(Part)." FireClient needs the player who's client is to be fired as the first argument. Try FireClient(Player, Part).

0

Also, it looks as if you are trying to create a bodyposition and a part in a local script. This will not work, as those changes will not replicate. Those changes should be made in the server script.

0

So do i put the same aruguments in OnClientEvent() So OnClientEvent(Player,Part)?

0

No, why pass the player in OnClientEvent?

0

For the OnClientEvent() the only argument you should need is Part. OnClientEvent(Part).

1 answer

###This is because the Players service is named Players, not Player. You also tried to fire a RemoteEvent to a BasePart, which will throw an error. You also do NOT pass the player in OnClientEvent, as the server fires that remote, not the player. Simply just pass the Part.

local Players = game:GetService('Players')
local Player = Players.LocalPlayer	

game.ReplicatedStorage.DoDun.OnClientEvent:Connect(function(Part)
    local bp = Instance.new("BodyPosition")
    bp.P = 20000  
    bp.Position = Player.Character:GetPrimaryPartCFrame() + CFrame.new(-2,0,0).p -- CFrame has no position property! it has a p tho!
    bp.Parent = Part -- parent last!
    wait()
    bp:Destroy()
end)

-- Server! 

game.Players.PlayerAdded:Connect(function(Player)
        local Part = game.ReplicatedStorage["Creation Replicator"]:Clone()
        -- clone from only one or the other! there will be 2 parts if cloned from both!
        Part.Parent = workspace
while true do
    wait()          
    game.ReplicatedStorage.DoDun:FireClient(Player, Part) -- send player and part!
end
end)


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