Good Evening,
I am having trouble with getting a part to move to a random location with a function fired by a Remote Event from a local script. However, the part will move for the server, but not for the client. I am not great with Client-Server related stuff just yet, so I am unsure on how to solve this. Here’s the script, it is a part of a server script under the model:
-- Variables
local user
local event = game.ReplicatedStorage.SendAISOut
local gbEvent = game.ReplicatedStorage.BeginGame
local noob = script.Parent
local touches = 0
-- Functions
game.Players.PlayerAdded:Connect(function(plyr) -- Player Script
user = plyr
end)
script.Parent.Touched:connect(function(obj) -- Touched Script
if game.Players:GetPlayerFromCharacter(obj.Parent) then
local hp = user.Backpack:FindFirstChild("HotPockets") -- Finds Items
local ed = user.Backpack:FindFirstChild("EnergyDrink")
local qu = user.Backpack:FindFirstChild("Quarter")
if hp then
hp:Destroy()
noob.mine_now:Play()
noob.Position = Vector3.new(-117.75, 4, 63.5) -- Goes Back to 1st Position
noob.Position = Vector3.new(0, 180, 0)
elseif ed then
noob.mine_now:Play()
ed:Destroy()
noob.Position = Vector3.new(-117.75, 4, 63.5) -- Goes Back to 1st Position
noob.Position = Vector3.new(0, 180, 0)
elseif qu then
noob.mine_now:Play()
qu:Destroy()
noob.Position = Vector3.new(-117.75, 4, 63.5) -- Goes Back to 1st Position
noob.Position = Vector3.new(0, 180, 0)
else
touches += 1
wait()
if touches == 1 then
noob.no_pass:Play()
wait(8)
touches = 0
end
end
else
-- NPC
end
end)
local function nextPosition()
wait(math.random(1,1)) -- Change to 60,220
local ranNum = math.random(1,1)
if ranNum == 1 then
noob.Position = Vector3.new(38, 5, 31.25)
noob.Orientation = Vector3.new(0, 90, 0)
elseif ranNum == 2 then
noob.Position = Vector3.new(-4, 5, 114.25)
noob.Orientation = Vector3.new(0, 90, 0)
elseif ranNum == 3 then
noob.Position = Vector3.new(-10.25, 5, 127)
noob.Orientation = Vector3.new(0, 180, 0)
elseif ranNum == 4 then
noob.Position = Vector3.new(26.25, 5, 97)
noob.Orientation = Vector3.new(0, 180, 0)
end
noob.give_great:Play()
print("Noob Moved!")
end
gbEvent.OnServerEvent:Connect(nextPosition)
I’m not sure why it is not working for the client. As I have said, I am still trying to understand more aspects of Client-Server scripting, so I am not great at it. What am I doing wrong?