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

My script that moves a block when you press a button is not really working out?

Asked by 4 years ago

For some reason this script does not really work? could it be the type of script i'm using? Im not too sure.

This is the script.

local UIS = game:GetService("UserInputService")
local MainBlock = game.Workspace.MainBlock

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.W then
        MainBlock.Position = Vector3.new(MainBlock.Position.X + 2,MainBlock.Position.Y,MainBlock.Position.Z)
    end
end)

I am using a regular script, not local if that helps.

0
Hey, I just got some change on my answer, hope it help you. Block_manvn 395 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

What your trying to achieve is not gonna work.(Unless it's filteringenabled = false) What you need to do is use a localscript to get input and change the position server side

--localscript
local UIS = game:GetService("UserInputService")
local MainBlock = game.Workspace.MainBlock
local remote = game.ReplicatedStorage.Mainblock -- whatever it's called

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.W then      remote:FireServer(CFrame.new(MainBlock.Position.X+2,MainBlock.Position.Y,MainBlock.Position.Z))
    end
end)

--serverscript
local remote = game.ReplicatedStorage.Mainblock
local MainBlock = game.Workspace.MainBlock

remote.OnServerEvent:Connect(function(plr, pos)
    MainBlock.Position = pos
end)

Make sure there's a remote called Mainblock or whatever. If your wondering why I used a remote event it's because if u change the position locally only the player will see it and not the other players.

--click detector
--put script inside the clickdetector
--put clickdetector inside MainBlock
--must be a regular script

local click = script.Parent
local MainBlock = click.Parent

click.MouseClick:Connect(function(plr)
    MainBlock.CFrame = CFrame.new(MainBlock.Position.X+2,MainBlock.Position.Y,MainBlock.Position.Z)
end)
0
I think ClickDetector is work better, you won't need a RemoteEvent for it. Block_manvn 395 — 4y
0
shall i edit it? HappyTimIsHim 652 — 4y
0
No, you will get a copyright-strike if you do that >:( Block_manvn 395 — 4y
Ad
Log in to vote
0
Answered by
shackfu 14
4 years ago

Don't use a regular script if you're trying to get input from the player. Put it in a local script.

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think you can make a button (you can do that by simply add ClickDetector into some kind of part, etc...)

In that button, insert a script (server type) and put this:

local clickDetector = script.Parent.ClickDetector

clickDetector.MouseClick:Connect(function()
    MainBlock.Position=Vector3.new(MainBlock.Position.X+2,
    MainBlock.Position.Y, MainBlock.Position.Z)
end)

EDIT: Well, here the change: So if you want the camera focus to the part, you have to put some RemoteEvent:

*ServerScript

local clickDetector = script.Parent.ClickDetector
local reEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local mainPosition = MainBlock.Position

clickDetector.MouseClick:Connect(function()
    MainBlock.Position=Vector3.new(MainBlock.Position.X+2,
    MainBlock.Position.Y, MainBlock.Position.Z)
    reEvent:FireCilent(plr, mainPosition)
end)

*LocalScript:

local camera = workspace.CurrentCamera
local reEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

reEvent.OnCilentEvent:Connect(function(position)
    camera.CFrame = CFrame.new(camera.Position, position)
end)

Hope this help you.

0
Wonderful idea, but the game is about a single block traveling while the camera is focused on that single block. Still thank you! roblox136393 32 — 4y
Log in to vote
0
Answered by 4 years ago

You'll have to put it in a local script as if you want to get input from a specific player you'll need a Local Script, except for that everything looks good!

Answer this question