Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i send arguments from Client to Server?

Asked by 5 years ago

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)

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). iColorDev -2 — 5y
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. iColorDev -2 — 5y
0
So do i put the same aruguments in OnClientEvent() So OnClientEvent(Player,Part)? GGButNO_RE 61 — 5y
0
No, why pass the player in OnClientEvent? User#19524 175 — 5y
0
For the OnClientEvent() the only argument you should need is Part. OnClientEvent(Part). iColorDev -2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)


Ad

Answer this question