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

Why does my script work In Play Solo, but not Start Server / Published to Roblox?

Asked by
Xduel 211 Moderation Voter
10 years ago

So here is my Script using .Touched and .KeyDown .

function debounce(func)
    local isRunning = false 
    return function(...)     
        if not isRunning then
            isRunning = true

            func(...)  

            isRunning = false
        end
    end
end

script.Parent.Touched:connect(debounce(function(player)
    if player.Parent and game.Players:GetPlayerFromCharacter(player.Parent) then
    plr = game.Players:GetPlayerFromCharacter(player.Parent)
print("Work1")
    mouse = plr:GetMouse()
        mouse.KeyDown:connect(function(key)
            if key:lower() == "r" then
            print("Work2")
            game.Workspace.Int.Value = true
            end
        end)
    end
end))

So as you see, when the player touch's the brick, it is supposed to print "Work1". This works fine in Play Solo, but will not print using Start Server. Why does this not work? All help appreciated, Thank You. ~ Xduel

1 answer

Log in to vote
1
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

Join the game in online mode and press F9 to open the developer console. Are there any errors?

Edit: The GetMouse function only works via LocalScript. You will have to listen for collisions client-side. Here's a quote from the wiki page:

Local: This item should be used with a LocalScript in order to work as expected in online mode.

0
One comes up that reads "An Error Has Occured", but that is one I have always gotten. I switched to see what was happening on the server's screen rather than Players, and got "Workspace.Part.Script:20: attempt to index global 'mouse' (a nil value)" Xduel 211 — 10y
0
Oh, Strange how it works in Play Solo. Must have to do with the server. Now this may be to much to ask, but do you have any suggestions for other methods to get the players mouse? Don't feel like you have to answer, I can always research it, Xduel 211 — 10y
0
There is no way to get a player's mouse server side, as it only exists to the client (just like the player's camera). I recommend either completely converting your script to a LocalScript distributed with StarterPack, or use BindableEvents to communicate between this script and a client sided script. MrFlimsy 345 — 10y
0
Bindable Events? I've heard of BIndable variables, I'll go research that. Thank You for the help! Xduel 211 — 10y
0
Anytime! MrFlimsy 345 — 10y
Ad

Answer this question