Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

5 comments

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)"

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,

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.

0

Bindable Events? I've heard of BIndable variables, I'll go research that. Thank You for the help!

0

Anytime!

This discussion is preserved as it was. New answers, comments, and votes are closed.