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.
1 | local UIS = game:GetService( "UserInputService" ) |
2 | local MainBlock = game.Workspace.MainBlock |
3 |
4 | UIS.InputBegan:Connect( function (input) |
5 | if input.KeyCode = = Enum.KeyCode.W then |
6 | MainBlock.Position = Vector 3. new(MainBlock.Position.X + 2 ,MainBlock.Position.Y,MainBlock.Position.Z) |
7 | end |
8 | end ) |
I am using a regular script, not local if that helps.
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 |
02 | local UIS = game:GetService( "UserInputService" ) |
03 | local MainBlock = game.Workspace.MainBlock |
04 | local remote = game.ReplicatedStorage.Mainblock -- whatever it's called |
05 |
06 | UIS.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 |
09 | end ) |
10 |
11 | --serverscript |
12 | local remote = game.ReplicatedStorage.Mainblock |
13 | local MainBlock = game.Workspace.MainBlock |
14 |
15 | remote.OnServerEvent:Connect( function (plr, pos) |
16 | MainBlock.Position = pos |
17 | 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.
01 | --click detector |
02 | --put script inside the clickdetector |
03 | --put clickdetector inside MainBlock |
04 | --must be a regular script |
05 |
06 | local click = script.Parent |
07 | local MainBlock = click.Parent |
08 |
09 | click.MouseClick:Connect( function (plr) |
10 | MainBlock.CFrame = CFrame.new(MainBlock.Position.X+ 2 ,MainBlock.Position.Y,MainBlock.Position.Z) |
11 | end ) |
Don't use a regular script if you're trying to get input from the player. Put it in a local script.
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:
1 | local clickDetector = script.Parent.ClickDetector |
2 |
3 | clickDetector.MouseClick:Connect( function () |
4 | MainBlock.Position = Vector 3. new(MainBlock.Position.X+ 2 , |
5 | MainBlock.Position.Y, MainBlock.Position.Z) |
6 | end ) |
EDIT: Well, here the change: So if you want the camera focus to the part, you have to put some RemoteEvent:
*ServerScript
1 | local clickDetector = script.Parent.ClickDetector |
2 | local reEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "RemoteEvent" ) |
3 | local mainPosition = MainBlock.Position |
4 |
5 | clickDetector.MouseClick:Connect( function () |
6 | MainBlock.Position = Vector 3. new(MainBlock.Position.X+ 2 , |
7 | MainBlock.Position.Y, MainBlock.Position.Z) |
8 | reEvent:FireCilent(plr, mainPosition) |
9 | end ) |
*LocalScript:
1 | local camera = workspace.CurrentCamera |
2 | local reEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "RemoteEvent" ) |
3 |
4 | reEvent.OnCilentEvent:Connect( function (position) |
5 | camera.CFrame = CFrame.new(camera.Position, position) |
6 | end ) |
Hope this help you.
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!