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
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
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!