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

Getting mouse from Player in a server script?

Asked by 7 years ago

Hello, I'm trying to make a tool that gives the player a Roblox gear when it's clicked using InsertService, but it has to be in a server script for that to work. Does the script have to be a localscript for getting the player's mouse?

Also, the tool works fine in Studio, but in-game it prints "Equipped" and "Found player" and then nothing else.

Here's the script (serverscript)

gears = {170896461, 257810065, 365674685, 319656339}

local Tool = script.Parent


    Tool.Equipped:connect(function(Mouse)
    print("equipped!")  
    local ply = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
    print("found player!")
    Mouse.Button1Down:connect(function()
        print("mouse down!")
        wait(1)
        local model = game:GetService("InsertService"):LoadAsset(gears[math.random(#gears)])
            for _,v in pairs(model:GetChildren()) do
                if v:IsA("Tool") or v:IsA("HopperBin") then
                    v.Parent = ply.Backpack
                        print("got model!")
                        script.Parent:Destroy()

    end
    end
    end)
    end)
1
Why are you handling a tool inside of a Server Script? AstrealDev 728 — 7y
1
You should never need the player's mouse from the server, it's just illogical. You should consider moving all of this to a local script, where it belongs. Same goes for any other code specific to a single user. ScriptGuider 5640 — 7y
1
If you need to do something from a server script just use a remote event or a remote function Perci1 4988 — 7y
0
I've been told that :LoadAsset only works on a server script, I'm not totally sure how to use remote events, but I'll look into it. SpazzMan502 133 — 7y
0
Here's a video tutorial I made on them: https://www.youtube.com/watch?v=4Dc_bri9mjs ScriptGuider 5640 — 7y

Answer this question