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

Why does this LocalScript work only for emulators?[Keybind, UserInputType&Service]

Asked by 5 years ago
local UIS = game:GetService("UserInputService") -- Service used to get the key pressed by a player

UIS.InputBegan:Connect(function(input,gameProcessed)

if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Gamepad1 or input.UserInputType == Enum.UserInputType.Gamepad2 or input.UserInputType == Enum.UserInputType.Touch then

if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.ButtonX then -- for keyboards and XBOX Controllers

if UIS:GetFocusedTextBox() == nil then

for i,v in pairs(game.Workspace.Stove["Stove1"]:GetChildren()) do

local mag = (v.Parent.Union.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude

if mag <= 10 then

local stoveLevel = v.Parent.stoveLevel -- A boolValue

game.ReplicatedStorage.StoveCall:FireServer("Stove",StoveLevel.Value)

end

end

end

end

script.Parent.MouseButton1Click:Connect(function()

if UIS:GetFocusedTextBox() == nil then

for i,v in pairs(game.Workspace.Stove["Stove1"]:GetChildren()) do

local mag = (v.Parent.Union.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude

if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then


local StoveLevel = v.Parent.StoveLevel

game.ReplicatedStorage.StoveCall:FireServer("Stove",StoveLevel.Value)

end

end

end

end)

end

end)



while wait() do

script.Parent.Visible = false

for i,v in pairs(game.Workspace.Stove["Stove1"]:GetChildren()) do

local stove = v.Parent

mag = (stove.Union.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude

if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then

local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(lucky.Union.Position)

script.Parent.Visible = true

script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)

script.Parent.TextLabel.Text = "Open 'Stove'"

end



end

end

Okay. This LocalScript is inside StarterGui > Keybind > ImageButton. if a player gets near the stove a Gui[with WSP] will popup, if you click the 'E' button, it will FireServer a RemoteEvent ~~and a script in ServerScriptService will print the stove level and the player's name.~~ But I expected that if you click with a computer mouse, it will work the same, but the

script.Parent.MouseButton1Click:Connect(function()

will only work when using emulators(touch). How would I make it so that it will work in computer mouses?

0
Sorry if your eyes hurt about indenting. In Studio it is indented but once I copy&pasted, it didn't indent the code tree_tree00 48 — 5y
0
UIS.InputBegan then if input.UserInputType == Enum.UserInputType.MouseButton1 then DeceptiveCaster 3761 — 5y
0
You're actually detecting things after that that are irrelevant to the mouse using KeyCode. DeceptiveCaster 3761 — 5y
0
? tree_tree00 48 — 5y
View all comments (2 more)
0
I don't understand can you give me a fix? tree_tree00 48 — 5y
0
b a d i n d e n t a t i o n LoganboyInCO 150 — 5y

Answer this question