Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Placement System Will Not Work Currectly When InvokedServer??

Asked by
AIetheo 236 Moderation Voter
3 years ago
Edited 3 years ago

I made this placement system but it will not work.

LocalScript Inside of StarterPack:

local Player = game.Players.LocalPlayer
local Base = Player:WaitForChild("base")
local Money = Player:WaitForChild("Money")
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Items = ReplicatedStorage.Items
local PlaceItem = ReplicatedStorage.PlaceItem
local ItemTable = {}
local PlacingItem = {}

for i,v in pairs(Items:GetChildren()) do
    table.insert(ItemTable,v)
end

function GetPlacingItem()
    for i,v in pairs(PlacingItem) do
        return v.Name
    end
end

UIS.InputBegan:Connect(function(Key,GPE)
    if Key.KeyCode == Enum.KeyCode.E and not GPE then
        local index = math.random(1,#ItemTable)
        table.insert(PlacingItem,ItemTable[index])
--      local RealItem = Items[GetPlacingItem()]:Clone()
        if Mouse.Target == Base.Value then
            PlaceItem:InvokeServer(PlacingItem,true)

        end
    end
end)

Script Inside of ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceItem = ReplicatedStorage.PlaceItem

function PlaceItem.OnServerInvoke(Player,Item,MouseOnBase)
    if MouseOnBase then
        local Mouse = Player:GetMouse()
        Mouse.Move:Connect(function()
            for i,v in pairs(Item) do
                local RealItem = ReplicatedStorage.Items[v.Name]:Clone()
                RealItem.Parent = game.Workspace.CurrentCamera
                RealItem:SetPrimaryPartCFrame(Mouse.Hit.p)
            end
        end)
    end
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

2 answers

Log in to vote
1
Answered by 3 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. AIetheo 236 — 3y
Ad
Log in to vote
0
Answered by 3 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:

PlaceItem:InvokeServer(PlacingItem,true)

For your Server Script do this:

function PlaceItem.OnServerInvoke(Player,Item,MouseOnBase)
    if MouseOnBase then
        local Mouse = Player:GetMouse()
        Mouse.Move:Connect(function()
            for i,v in pairs(Item) do
                local RealItem = ReplicatedStorage[v]:Clone()
                RealItem.Parent = game.Workspace.CurrentCamera
                RealItem:SetPrimaryPartCFrame(Mouse.Hit.p)
            end
        end)
    end
end
0
All It Does Is Create Multiple Items And Only Puts Them All In One Spot, It doesn't move where the mouse moves. AIetheo 236 — 3y

Answer this question