What do you want to achieve?
i want to make the player move if the player clicks a button.This is for a 2d game
What is the issue?
After i click nothing happens no error too
What solutions have you tried so far?
checked the dev hub and devforum
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local localPlayer = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
RunService:BindToRenderStep("move",Enum.RenderPriority.Character.Value + 1,function()
script.Parent.MouseButton1Click:Connect(function()
if localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:Move(Vector3.new(1, 0, 0), true)
end
end
end)
end)
Here, I found a simialir script to yours, I got it from the wiki. I belive your script is wrote wrong. Try this:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
RunService:BindToRenderStep("move",
-- run after the character
Enum.RenderPriority.Character.Value + 1,
function()
if localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:Move(Vector3.new(0, 0, -1), true)
end
end
end
)
Try this script I made that should move the player while the button is being pressed down.
local button = script.Parent
local plr = game.Players.LocalPlayer
local character -- Contains the character.
if plr.Character then
character = plr.Character
end
plr.CharacterAdded:Connect(function(char)
-- Character for player has been loaded agian.
character = char
end)
button.MouseButton1Down:Connect(function()
if character then
character.Humanoid:Move(Vector3.new(0, 0, -1), true)
end
end)
Also why you are implementing 2 functions encased in each other? You can easily watch for when the Character moves by just the MouseButton1Click event
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
Player:Move(Vector3.new(0, 0, -1), false)
end)
Also, if you want world coordinates but not where the camera is pointing at, set the second parameter to false
local button = script.Parent
local plr = game.Players.LocalPlayer
local character -- Contains the character.
if plr.Character then
character = plr.Character
end
plr.CharacterAdded:Connect(function(char)
-- Character for player has been loaded agian.
character = char
end)
button.MouseButton1Click:Connect(function()
if character then
plr:Move(Vector3.new(0,0,-1), false)
character.Humanoid:Move(Vector3.new(0, 0, -1), false)
end
end)
The character variable is only dependent on just getting the Player's Character, you aren’t checking for a CharacterAdded:Wait() event to yield until a character has been found
Use the code I tried, it should belong parented inside the buttont
The only thing I can see is that your Player’s controls are overriding the Move function, can you try disabling the controls with this?
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent
local PlayerControls = require(Player.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerControls:GetControls()
Button.MouseButton1Click:Connect(function()
Controls:Disable()
Player:Move(Vector3.new(0, 0, -1), false)
end)
local button = script.Parent
local player = game.Players.LocalPlayer
button.MouseButton1Click:Connect(function()
player.Character:MoveTo(Vector3.new(1, 0, 0))
end)