Changing properties locally

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)
3 Likes

You would use RemoteEvents and do the tween on the client.

3 Likes

All you need to do is put it in a local script.

1 Like

If you read my post you can see I have tried that

1 Like

I read the post but didn’t see that for some reason. To cause events between Server and Client, use RemoteEvents as @COUNTYL1MITS said.

2 Likes

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

1 Like

Yeah, I have tested it with two accounts. Right now I’m reading a tutorial on RemoteEvents as that seems to be the probable solution

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)

You cannot get a local player in a server.

Try this

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenObject = ReplicatedStorage:WaitForChild("TweenObject")

TweenObject.OnServerEvent:Connect(function(Player, LP, Tweened)
local TweenService = game:GetService("TweenService")
local Tweened = game.Workspace.Terrain
local goal = {}
goal.WaterColor = Color3.fromRGB(255,0,0)
local tweenInfo = TweenInfo.new(5)
local tweenTerrain = TweenService:Create(Tweened, tweenInfo, goal)
	tweenTerrain:Play()
end)

Do not change anything locally roblox knows what the player is in parameters.

Nope, that script shows the same results

Change the name Terrain to “TestingPart”

Can you explain what that is supposed to do. This is the script in serverscriptservice as of now.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenObject = ReplicatedStorage:WaitForChild("TweenObject")

TweenObject.OnServerEvent:Connect(function(Player, TestingPart)
	local TweenService = game:GetService("TweenService")
	local goal = {}
	goal.WaterColor = Color3.fromRGB(255,0,0)
	local tweenInfo = TweenInfo.new(5)
	local tweenTerrain = TweenService:Create(TestingPart, tweenInfo, goal)
	tweenTerrain:Play()
end)

I just had a thought, is terrain not able to be locally changed for a client?