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

Placement System Will Not Work Currectly When InvokedServer??

Asked by
LuaDLL 253 Moderation Voter
7 years ago
Edited 7 years ago

I made this placement system but it will not work.

LocalScript Inside of StarterPack:

01local Player = game.Players.LocalPlayer
02local Base = Player:WaitForChild("base")
03local Money = Player:WaitForChild("Money")
04local UIS = game:GetService("UserInputService")
05local Mouse = Player:GetMouse()
06local ReplicatedStorage = game:GetService("ReplicatedStorage")
07local Items = ReplicatedStorage.Items
08local PlaceItem = ReplicatedStorage.PlaceItem
09local ItemTable = {}
10local PlacingItem = {}
11 
12for i,v in pairs(Items:GetChildren()) do
13    table.insert(ItemTable,v)
14end
15 
View all 32 lines...

Script Inside of ServerScriptService:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local PlaceItem = ReplicatedStorage.PlaceItem
03 
04function 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
15end

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

2 answers

Log in to vote
1
Answered by 7 years ago

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.

0
Thank you. LuaDLL 253 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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:

1PlaceItem:InvokeServer(PlacingItem,true)

For your Server Script do this:

01function 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
12end
0
All It Does Is Create Multiple Items And Only Puts Them All In One Spot, It doesn't move where the mouse moves. LuaDLL 253 — 7y

Answer this question