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

How to copy a LocalScript from ServerStorage and put it into the local players GUI?

Here is what I have:

local OnTouchSky = game.ServerStorage.SkyChanger
local OnTouchSkyCopy = OnTouchSky:Clone()

function onTouched(hit)
	
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

OnTouchSkyCopy.Parent = game.Players.LocalPlayer.PlayerGui

script.Parent.Touched:Connect(onTouched)
end

There are no errors and I honestly have no idea what I'm doing wrong. I'm trying to make a script that when you touch a brick, it copies and pastes a LocalScript from ServerStorage into PlayerGui (so the skybox changes)

LocalScript:

if game.Players.LocalPlayer.Name == "Player1" then
b = Instance.new("Sky") 
b.Parent = game.Lighting 
b.SkyboxBk = "rbxassetid://591058823" 
b.SkyboxDn = "rbxassetid://591059876" 
b.SkyboxFt = "rbxassetid://591058104" 
b.SkyboxLf = "rbxassetid://591057861" 
b.SkyboxRt = "rbxassetid://591057625" 
b.SkyboxUp = "rbxassetid://591059642" 
end

NOTE: I am not sure if the LocalScript isn't working or it just ain't pasting into PlayerGui. Or should it be in StarterGui, it is only able for the local player who touches the brick that changes the skybox, it doesn't change for anyone else. Please help

2 answers

✓ Accepted answer

the issue is your using a local script to try to access the ServerStorage which regardless of what cherrythetree thought you can access but only with Server Scripts local scripts run on the client only and the client cannot see ServerStorage or ServerScriptService and of course ServerScripts can so you would have to use

Script:

local OnTouchSky = game.ServerStorage.SkyChanger
local OnTouchSkyCopy = OnTouchSky:Clone()
local Players = game:GetService('Players')

function onTouched(hit)
local Player = Players:FindFirstChild(hit.Parent.Name)
OnTouchSkyCopy.Parent = Player.PlayerGui
script.Parent.Touched:Connect(onTouched)
end

and that should work out just fine i didn't test it myself though but definitely let me know! --Donut792#1329

1 comment

0

It works, but script.Parent.Touched:Connect(onTouched) needs to be after end. Is there any specific reason for that? Also, now I'm having trouble when the player touches both sky changer brick the scripts stay

It is impossible to copy something from the ServerStorage and ServerScriptService because you only have the access to it while your editing the game, just put the LocalScript inside ReplicatedStorage and then there you go.

local OnTouchSky = game.ReplicatedStorage.SkyChanger
local OnTouchSkyCopy = OnTouchSky:Clone()

function onTouched(hit)
	local player = game.Players:GetPlayerFromCharacter(hit)
	if player then
		OnTouchSkyCopy.Parent = player.PlayerGui
	end
end
script.Parent.Touched:Connect(onTouched)

EDITED!

3 comments

0

@CherryTheTree It still does not work, there is no error, when I test there is no 'SkyChanger' in PlayerGui

0

anyways because the sky class only works at lighting and not playergui

0

I have it in StarterGui, I'll just have to find a way around it. thanks anyway!

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