Roblox cant change object parent in server script

hello!i have been making a script that changes a guis parent to playergui in a server script but it doesnt work!i have searched devforum for an answer but all of them were not server script but local script…

2 Likes

What’s the code you are using?

2 Likes

Client :

wait()
game.Players.LocalPlayer:GetMouse().Icon = "rbxassetid://10883840867"
game.Players.LocalPlayer.PlayerGui.Movement.ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Root = LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local Mouse, Camera  = LocalPlayer:GetMouse(), Workspace.CurrentCamera
local angleX, x, y, tilt, vX, vY, sX, sY = 0, 0, 0, 0, 0, 0, 10, 10
local TouchEnabled = UserInputService.TouchEnabled
local randomX, randomY = nil, nil
local keycode = nil
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui.StatisticsPage
local statremote = game.ReplicatedStorage.SendStatistics
local sentstat = "nil"
local sentdata = "nil"
local function lerp(v1, v2, t)
	return v1 + (v2 - v1) * t
end

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)
game.Players.LocalPlayer.CameraMaxZoomDistance = 0.5
Camera.FieldOfView = 90

RunService.RenderStepped:Connect(function(dt)
	local velocity = Root.Velocity.magnitude
	if velocity > 0.02 then dt *= 60 randomX = math.random(1, 2) randomY = math.random(1, 2) --x(10,15), y(5,10)
		vX = dt <= 2 and lerp(vX, math.cos(tick() * 0.5 * randomX) * (math.random(5, 20) / 200) * dt, 0.05 * dt) or 0
		vY = dt <= 2 and lerp(vY, math.cos(tick() * 0.5 * randomY) * (math.random(2, 10) / 200) * dt, 0.05 * dt) or 0

		Camera.CFrame *= CFrame.Angles(0, 0, math.rad(angleX))
			* CFrame.Angles(math.rad(math.clamp(x * dt, -0.15, 0.15)), math.rad(math.clamp(y * dt, -0.5, 0.5)), tilt)
			* CFrame.Angles(math.rad(vX), math.rad(vY), math.rad(vY * 10))

		tilt = math.clamp(lerp(tilt, -Camera.CFrame:VectorToObjectSpace((Root and Root.Velocity or 
			Vector3.new()) / math.max(LocalPlayer.Character.Humanoid.WalkSpeed, 0.01)).X * 0.05, 0.1 * dt), -0.05, 0.05)

		if not TouchEnabled and dt < 2 then
			angleX = lerp(angleX, math.clamp(UserInputService:GetMouseDelta().X / dt * 0.15, -2.5, 2.5), 0.25 * dt)
		end x = lerp(x, math.sin(tick() * sX) / 5 * math.min(1, sY / 10), 0.25 * dt)
		y = velocity > 1 and lerp(y, math.cos(tick() * 0.5 * math.floor(sX)) * (sX / 200), 0.25 * dt) or lerp(y, 0, 0.05 * dt)
		sX, sY = velocity > 12 and 20 or (velocity > 0.1 and 12 or 0), velocity > 0.1 and 18 or (velocity > 0.1 and 14 or 0)
	end
end)

UserInputService.InputBegan:Connect(function(io)
	keycode = io.KeyCode
	while keycode == Enum.KeyCode.LeftShift do
		game.ReplicatedStorage.Sprinting:FireServer()
		wait()
	end
	if io.KeyCode == Enum.KeyCode.Tab then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.StatisticsPage.Visible = not game.Players.LocalPlayer.PlayerGui.ScreenGui.StatisticsPage.Visible
		game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible = not game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible
		if game.Players.LocalPlayer.PlayerGui.ScreenGui.StatisticsPage.Visible == false then
			game.Players.LocalPlayer:GetMouse().Icon = "rbxassetid://10883840867"
		end
		if game.Players.LocalPlayer.PlayerGui.ScreenGui.StatisticsPage.Visible == true then
			game.Players.LocalPlayer:GetMouse().Icon = ""
		end
	end
	if io.KeyCode == Enum.KeyCode.F9 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible = not game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible
		if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible == false then
			game.Players.LocalPlayer:GetMouse().Icon = "rbxassetid://10883840867"
		end
		if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Visible == true then
			game.Players.LocalPlayer:GetMouse().Icon = ""
		end
	end
end)

UserInputService.InputEnded:Connect(function(io)
	if io.KeyCode == Enum.KeyCode.LeftShift then
		keycode = nil
		game.ReplicatedStorage.StopSprinting:FireServer()
		wait()
	end
end)

statremote.OnClientEvent:Connect(function(stat)
	sentstat = stat
end)

game.ReplicatedStorage.SendConnectionData.OnClientEvent:Connect(function(data)
	sentdata = data
end)

while true do
	wait()
	gui.WS.Text = "ws"..game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
	gui.JP.Text = "jh"..game.Players.LocalPlayer.Character.Humanoid.JumpHeight
	gui.SPRINT.Text = sentstat.." st *ns"
	if sentdata == "yes" then
		gui.SC.Text = "yes"
		gui.SC.TextColor3 = Color3.fromRGB(0,255,0)
	end
	if sentdata == "no" then
		gui.SC.Text = "no"
		gui.SC.TextColor3 = Color3.fromRGB(255,0,0)
	end
	if sentdata == "nil" then
		gui.SC.Text = "nil"
		gui.SC.TextColor3 = Color3.fromRGB(255,255,0)
	end
	sentdata = "no"
end
wait(3)
game.ReplicatedStorage.SendConnectionData:FireServer()

Server :

local TweenService = game:GetService("TweenService")
local sprintingTime = 0
local remote = game.ReplicatedStorage.Sprinting
local stopremote = game.ReplicatedStorage.StopSprinting
local statremote = game.ReplicatedStorage.SendStatistics

function startCheckingAgain()
	while sprintingTime <= 15 do
		if sprintingTime <= 15 then
			sprintingTime = sprintingTime + 1
		end
		wait(1)
	end
end

function Tween(ins,tim,props)
	TweenService:Create(ins,TweenInfo.new(tim,Enum.EasingStyle.Quart,Enum.EasingDirection.InOut,0,false,0),props):Play()
end

startCheckingAgain()

remote.OnServerEvent:Connect(function(plr)
	if sprintingTime <= 15 then
		Tween(plr.Character.Humanoid,0.01,{WalkSpeed = 26})
	end
	while sprintingTime >= 15 do
		Tween(plr.Character.Humanoid,0.01,{WalkSpeed = 16})
		wait()
	end
	while true do
		wait()
		statremote:FireClient(plr,sprintingTime)
		game.ReplicatedStorage.SendConnectionData:FireClient(plr,"yes")
	end
end)

stopremote.OnServerEvent:Connect(function(plr)
	if sprintingTime >= 15 then
		wait(2)
		sprintingTime = 0
		startCheckingAgain()
	end
	Tween(plr.Character.Humanoid,0.01,{WalkSpeed = 16})
end)

game.ReplicatedStorage.SendConnectionData.OnServerEvent:Connect(function(plr)
	plr.PlayerGui.Movement.ScreenGui.Parent = plr.PlayerGui
end)

by the way,the remote event im using is “SendConnectionData”

1 Like