I made this placement system but it will not work.
LocalScript Inside of StarterPack:
01 | local Player = game.Players.LocalPlayer |
02 | local Base = Player:WaitForChild( "base" ) |
03 | local Money = Player:WaitForChild( "Money" ) |
04 | local UIS = game:GetService( "UserInputService" ) |
05 | local Mouse = Player:GetMouse() |
06 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
07 | local Items = ReplicatedStorage.Items |
08 | local PlaceItem = ReplicatedStorage.PlaceItem |
09 | local ItemTable = { } |
10 | local PlacingItem = { } |
11 |
12 | for i,v in pairs (Items:GetChildren()) do |
13 | table.insert(ItemTable,v) |
14 | end |
15 |
Script Inside of ServerScriptService:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local PlaceItem = ReplicatedStorage.PlaceItem |
03 |
04 | function PlaceItem.OnServerInvoke(Player,Item,MouseOnBase) |
05 | if MouseOnBase then |
06 | local Mouse = Player:GetMouse() |
07 | Mouse.Move:Connect( function () |
08 | for i,v in pairs (Item) do |
09 | local RealItem = ReplicatedStorage.Items [ v.Name ] :Clone() |
10 | RealItem.Parent = game.Workspace.CurrentCamera |
11 | RealItem:SetPrimaryPartCFrame(Mouse.Hit.p) |
12 | end |
13 | end ) |
14 | end |
15 | end |
Error:
12:29:20.244 - ServerScriptService.Data.PlaceMent:6: bad argument #2 to '?' (string expected, got Object)
12:29:20.245 - Stack Begin
12:29:20.246 - Script 'ServerScriptService.Data.PlaceMent', Line 6
12:29:20.246 - Stack End
12:29:20.247 - ServerScriptService.Data.PlaceMent:6: bad argument #2 to '?' (string expected, got Object)
12:29:20.248 - Stack Begin
12:29:20.249 - Script 'Players.FuriaI.Backpack.Placement', Line 28
12:29:20.249 - Stack End
You're going to run into a few errors, and you're going to have to revise your scripts.
The error you are getting right now is caused by line 6 of your server side script. In it, you write local Plr = game.Players[Player]
, where Player
is a Player Object
and not a string.
This might seem confusing, because you pass Player.Name
to the RemoteFunction. All Remote*
, however, receive the player who called them as the first argument of the server event. This means that your call, PlaceItem:InvokeServer(Player.Name, PlacingItem, true)
signals an event PlaceItem.OnServerInvoke(Player, Player.Name, PlacingItem, true)
on the server.
That said, the server side script that you've written will not work. A script on the server cannot retrieve a Mouse
.
All of the place
functionality will have to occur via a LocalScript in, for example, StarterPlayerScripts
.
PlaceItem:InvokeServer(Player.Name,PlacingItem,true)
This line sets the first argument of the OnServerEvent
function to Player already
For your Local Script change the InvokeServer
line to this:
1 | PlaceItem:InvokeServer(PlacingItem, true ) |
For your Server Script do this:
01 | function PlaceItem.OnServerInvoke(Player,Item,MouseOnBase) |
02 | if MouseOnBase then |
03 | local Mouse = Player:GetMouse() |
04 | Mouse.Move:Connect( function () |
05 | for i,v in pairs (Item) do |
06 | local RealItem = ReplicatedStorage [ v ] :Clone() |
07 | RealItem.Parent = game.Workspace.CurrentCamera |
08 | RealItem:SetPrimaryPartCFrame(Mouse.Hit.p) |
09 | end |
10 | end ) |
11 | end |
12 | end |