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

Key Inputs To Control Vector3?

I'm making a script that uses WASD to control the path of a tornado.

This is my keydown script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    if key == "a" then
	game.Workspace.Direction.Value = "West"
	elseif key == "w" then
	game.Workspace.Direction.Value = "North"
	elseif key == "s" then
	game.Workspace.Direction.Value = "South"
	elseif key == "d" then
	game.Workspace.Direction.Value = "East"
end
   
end)

and this is my tornado animation script:

while true do
	torx = script.Parent.Position.X
	torz = script.Parent.Position.Z
if game.Workspace.Direction.Value == "West" then
	x = torx-1
	script.Parent.Position = Vector3.new(x,96.5,torz)
	elseif game.Workspace.Direction.Value == "East" then
	x = torx+1
	script.Parent.Position = Vector3.new(x,96.5,torz)
	elseif game.Workspace.Direction.Value == "North" then
	z = torz-1
	script.Parent.Position = Vector3.new(torx,96.5,z)
	elseif game.Workspace.Direction.Value == "South" then
	z = torz+1
	script.Parent.Position = Vector3.new(torx,96.5,z)
else
	print"nuffin"
end
wait(1)
end

When I press the keys, the Direction value is telling me one of the 4 directions, but the tornado doesn't move. Note that the script keeps printing "nuffin", so it doesn't see the value change.

What can be done to fix this? Thanks!

1 comment

0

Xd I'm trying the same thing

1 answer

Hi! As you may know, because of FilteringEnabled, the client can't speak with the server directly.

If both scripts are local, ignore this, it is a wrong explanation.

If your LocalScript is modifying the value, but your server-side script can't see it, you might want to use remote events to change the value.

Here's a handy text tutorial. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

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