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

Userinputservice LocalScript working in roblox studio, but not online?

Asked by 6 years ago

Can anyone explain to me why this is happening?

local uis = game:GetService("UserInputService")





uis.InputBegan:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
if input.KeyCode == Enum.KeyCode.Left then
script.Parent.Value = -1
end
end
end)

uis.InputEnded:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
if input.KeyCode == Enum.KeyCode.Left then
script.Parent.Value = 0
end
end
end)

uis.InputBegan:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
if input.KeyCode == Enum.KeyCode.Right then
script.Parent.Value = 1
end
end
end)


uis.InputEnded:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
if input.KeyCode == Enum.KeyCode.Right then
script.Parent.Value = 0
end
end
end)
0
Is this in a script or localscript XAXA 1569 — 6y
0
@XAXA This is a local script. It also says that in the title. JoeRaptor 72 — 6y
0
Try moving the localscript to workspace. LeadRDRK 437 — 6y
1
@leadfordead2 The localscript is not supposed to be in Workspace though. JoeRaptor 72 — 6y
0
I found out my problem! I just had two scripts utilizing userinput service asigned to the same button! I just need to put all of my code pertaining to that in one LocalScript. THANK YOU SO MUCH! @XAXA JoeRaptor 72 — 6y

1 answer

Log in to vote
0
Answered by
cfiredog 274 Moderation Voter
6 years ago

It all depends on where you have placed the Local Script.

A LocalScript will only run Lua code if it is a descendant of one of the following objects: 1. A Player's Backpack, such as a child of a Tool

2. A Player's Character model

3. A Player's PlayerGui

4. A Player's PlayerScripts

5. The ReplicatedFirst service

Additionally, you should really only be using one RBXScriptSignal for each event like so:

local uis = game:GetService("UserInputService")


uis.InputBegan:Connect(function(input,gp)
    if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
        if input.KeyCode == Enum.KeyCode.Left then
            script.Parent.Value = -1
        end

        if input.KeyCode == Enum.KeyCode.Right then
            script.Parent.Value = 1
        end
    end
end)

uis.InputEnded:Connect(function(input,gp)
    if input.UserInputType == Enum.UserInputType.Keyboard and (not gp) then
        if input.KeyCode == Enum.KeyCode.Left then
            script.Parent.Value = 0
        end

        if input.KeyCode == Enum.KeyCode.Right then
            script.Parent.Value = 0
        end
    end
end)
Ad

Answer this question