Hello scripters, currently, I am trying to create a script with the information I have recently learned. It seems to go pretty well considering that it is indeed changing the properties. One problem insists, they change globally.
I am trying to make it so once the function within the script is fired, will change the properties of the selected objects for the local player that touched it. This is supposed to be used for ambience, lighting, etc.
This is the script I have worked out so far, works with script in the part itself and with a local script in the starterplayerscripts folder.
local TweenService = game:GetService("TweenService")
local Terrain = game.Workspace.Terrain
local hasTouched = false
local part = game.Workspace.T
Terrain.WaterColor = Color3.fromRGB(35, 124, 156)
local goal = {}
goal.WaterColor = Color3.fromRGB(4, 255, 0)
local tweenInfo = TweenInfo.new(15)
local tween1 = TweenService:Create(Terrain, tweenInfo, goal)
part.Touched:Connect(function(hit)
if hasTouched then
return
elseif not hasTouched then
hasTouched = true
if hit.Parent then
tween1:Play()
end
end
wait(1)
print(hasTouched)
end)
part.TouchEnded:Connect(function()
hasTouched = false
print(hasTouched)
end)
Are you sure the properties change globally?
If you press this button then it will show you what the server sees
https://gyazo.com/a286edda48f0ccd17ec928ee9afb3ee4
Edit i just noticed your changing the properties from a server script(right?) if you are then the properties will replicate to all clients as @COUNTYL1MITS said you have* to use remote events if you want the properties to be local
I tried this but the event was still visible to all clients. These are the new scripts I’ve created
Local script (In StarterPlayerScripts
local part = game.Workspace.Loo.AmbientController
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenObject = ReplicatedStorage:WaitForChild("TweenObject")
local Tweened = game.Workspace.Terrain
function debounce(func)
local isRunning = false
return function(...)
if not isRunning then
isRunning = true
func(...)
isRunning = false
end
end
end
part.Touched:Connect(debounce(function(LP)
if LP.parent then
TweenObject:FireServer(Tweened)
end
end))
Script (In ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenObject = ReplicatedStorage:WaitForChild("TweenObject")
local TweenService = game:GetService("TweenService")
local Tweened = game.Workspace.Terrain
local LP = game.Players.LocalPlayer
local goal = {}
goal.WaterColor = Color3.fromRGB(255,0,0)
local tweenInfo = TweenInfo.new(5)
local tweenTerrain = TweenService:Create(Tweened, tweenInfo, goal)
TweenObject.OnServerEvent:Connect(function(LP, Tweened)
tweenTerrain:Play()
end)