Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

Hey, I just got some change on my answer, hope it help you.

4 answers

✓ Accepted answer

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)

3 comments

0

I think ClickDetector is work better, you won't need a RemoteEvent for it.

0

shall i edit it?

0

No, you will get a copyright-strike if you do that >:(

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:

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.

1 comment

0

Wonderful idea, but the game is about a single block traveling while the camera is focused on that single block. Still thank 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!

This discussion is preserved as it was. New answers, comments, and votes are closed.