Changing properties through a server script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So, This is scary lary, he is a part in roblox studio:

    Highlighted part, and I was making a script were it would change the transparency, and change the bool value to false. Let me share it so it can make more sense.
    this is the Server Script were i change the properties (I believe this is were the issue is)
local barr = game.Workspace["Scary Lary"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SLA = ReplicatedStorage:WaitForChild("ScaryLaryACTIVATED")
SLA.OnServerEvent:Connect(function()
	barr.Cancollide = false
	barr.Transparency = 0.5
end)

this is the local script:


local barr = game.Workspace["Scary Lary"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SLA = ReplicatedStorage:WaitForChild("ScaryLaryACTIVATED")
game.Players.PlayerAdded:Connect(function(Plr)
	Plr.Chatted:Connect(function(msg)
		if Plr.UserId == "309099401" then
			if msg == "Le traître se noie" then
				SLA:FireServer()
			end
		end		
	end)
end)

I don’t know why its running, I’m trying to make it so everyone sees the part change properties when someone says something
Expected outcome when they say the word(properties change):


outcome i get when they say the word (the properties don’t change):

-- This is an example Lua code block

You typed bar.Cancollide = false instead of barr.CanCollide = false

1 Like

Sorry, there is a lot of typos, Here is the problem since its hard to read because of the typos:
I’m connecting everything through a remote function so everyone can see the part when they say the word

If you want it to happen on the client only then do this:

Local Script:

local barr = game.Workspace["Scary Lary"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SLA = ReplicatedStorage:WaitForChild("ScaryLaryACTIVATED")
SLA.OnClientEvent:Connect(function()
	barr.CanCollide = false
	barr.Transparency = 0.5
end)

Server Script:

local barr = game.Workspace["Scary Lary"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SLA = ReplicatedStorage:WaitForChild("ScaryLaryACTIVATED")
game.Players.PlayerAdded:Connect(function(Plr)
	Plr.Chatted:Connect(function(msg)
		if Plr.UserId == "309099401" then
			if msg == "Le traître se noie" then
				SLA:FireClient()
			end
		end		
	end)
end)

Ah ok, I changed it. Still doesn’t work, I think there is something else wrong besides that.

But, would all the players be able to see the property change?

@PinnacleFusion
If you want it to happen on server, then try this:

Server Script in ServerScriptService
local Players = game:GetService("Players")

local cache = {}
function getUsernameFromUserId(userId)
	if cache[userId] then return cache[userId] end
	local player = Players:GetPlayerByUserId(userId)
	if player then
		cache[userId] = player.Name
		return player.Name
	end 
	local name
	pcall(function ()
		name = Players:GetNameFromUserIdAsync(userId)
	end)
	cache[userId] = name
	return name
end

local barr = game.Workspace["Scary Lary"]
	
game.Players.PlayerAdded:Connect(function(Plr)	
Plr.Chatted:Connect(function(msg)
	if Plr.UserId == 309099401 and getUsernameFromUserId(309099401) == Plr.Name then
		if msg == "Le traître se noie" then
			barr.CanCollide = false
			barr.Transparency = 0.5
		   end
	    end		
	end)
end)		

Reminder: You can’t use string for UserId, it returns an IntValue. lol

whats the point of the change() function lol. Besides that redundancy I think that code is pretty good.

My first guess would be to change the UserId from a string to a number
if Plr.UserId == 309099401 then

2 Likes

Yeah thats true, i did mess up on that. But it still doesn’t work. hm

If you’re trying to do it on server, then try post. (#9)

Note: I have fully tested everything.

Ok, I’ll do it in the morning, It’ll most likely work. I’ll put this post as solved once im done with the script, thx!

I would not recommend the way you’re doing it right now. Since you’re ONLY going off a remote event, an exploiter can easily just fire the event and not have to worry about it.

Instead, what you should do is move the LocalScript onto the server. On the server, when a player joins, connect the .Chatted event, and if they match the text, and have the specified UserId, then change the properties. The Event firing from the client is a useless middleman, and can also cause security issues.

1 Like

No, the client isn’t allowed to change the player name, but I don’t see how it’s relevant to the post anyways.

Correction: Yes, most exploits are able to change protected strings such as UserId, or Name, but the client will not be able to change these protected strings if run on a LocalScript, and not in an exploit.

The OP themself said they wanted to change the parts for everyone, not just a single client.

1 Like

Plr.UserId == “309099401” , UserId returns an Int Not string
so do Plr.UserId == 309099401

Make the server script this:

local barr = game.Workspace:WaitForChild("Scary Lary")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SLA = ReplicatedStorage:WaitForChild("ScaryLaryACTIVATED")
SLA.OnServerEvent:Connect(function()
	barr.CanCollide = false
	barr.Transparency = 0.5
end)

And if that doesn’t work, please show me the errors in the output please.

1 Like