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 5 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.

1local UIS = game:GetService("UserInputService")
2local MainBlock = game.Workspace.MainBlock
3 
4UIS.InputBegan:Connect(function(input)
5    if input.KeyCode == Enum.KeyCode.W then
6        MainBlock.Position = Vector3.new(MainBlock.Position.X + 2,MainBlock.Position.Y,MainBlock.Position.Z)
7    end
8end)

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 — 5y

4 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 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

01--localscript
02local UIS = game:GetService("UserInputService")
03local MainBlock = game.Workspace.MainBlock
04local remote = game.ReplicatedStorage.Mainblock -- whatever it's called
05 
06UIS.InputBegan:Connect(function(input)
07    if input.KeyCode == Enum.KeyCode.W then      remote:FireServer(CFrame.new(MainBlock.Position.X+2,MainBlock.Position.Y,MainBlock.Position.Z))
08    end
09end)
10 
11--serverscript
12local remote = game.ReplicatedStorage.Mainblock
13local MainBlock = game.Workspace.MainBlock
14 
15remote.OnServerEvent:Connect(function(plr, pos)
16    MainBlock.Position = pos
17end)

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.

01--click detector
02--put script inside the clickdetector
03--put clickdetector inside MainBlock
04--must be a regular script
05 
06local click = script.Parent
07local MainBlock = click.Parent
08 
09click.MouseClick:Connect(function(plr)
10    MainBlock.CFrame = CFrame.new(MainBlock.Position.X+2,MainBlock.Position.Y,MainBlock.Position.Z)
11end)
0
I think ClickDetector is work better, you won't need a RemoteEvent for it. Block_manvn 395 — 5y
0
shall i edit it? HappyTimIsHim 652 — 5y
0
No, you will get a copyright-strike if you do that >:( Block_manvn 395 — 5y
Ad
Log in to vote
0
Answered by
shackfu 14
5 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 5 years ago
Edited 5 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:

1local clickDetector = script.Parent.ClickDetector
2 
3clickDetector.MouseClick:Connect(function()
4    MainBlock.Position=Vector3.new(MainBlock.Position.X+2,
5    MainBlock.Position.Y, MainBlock.Position.Z)
6end)

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

*ServerScript

1local clickDetector = script.Parent.ClickDetector
2local reEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
3local mainPosition = MainBlock.Position
4 
5clickDetector.MouseClick:Connect(function()
6    MainBlock.Position=Vector3.new(MainBlock.Position.X+2,
7    MainBlock.Position.Y, MainBlock.Position.Z)
8    reEvent:FireCilent(plr, mainPosition)
9end)

*LocalScript:

1local camera = workspace.CurrentCamera
2local reEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
3 
4reEvent.OnCilentEvent:Connect(function(position)
5    camera.CFrame = CFrame.new(camera.Position, position)
6end)

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 — 5y
Log in to vote
0
Answered by 5 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