Modifications to the above example(thank you very much good ser, that’s not spoon feeding right?)
First off, hierarchy
Server Script
local event = game.ReplicatedStorage.RemoteEvent
game.Players.PlayerAdded:Connect(function(player)
local part = workspace.Proxpart
local PromptSpeed = 2
event:FireAllClients(PromptSpeed, part)
print("Server fired event to " .. player.Name .. " with speed " .. PromptSpeed .. " and part " .. part.Name)
end)
Client Script
local event = game.ReplicatedStorage.RemoteEvent
event.OnClientEvent:Connect(function(PromptSpeed, part)
print("Client recieved event variable PromptSpeed: " .. PromptSpeed)
print("Client recieved event variable part: " .. part)
part.ProximityPrompt.HoldDuration = PromptSpeed
end)
Quick Note: FireAllClients does not need a player variable.
This would not work as the local script is unable to directly find the referenced part in the workspace, as stated in this error
05:49:25.965 Server fired event to EeveePikachu54 with speed 2 and part Proxpart - Server - Script:8
05:49:26.011 Client recieved event variable PromptSpeed: 2 - Client - LocalScript:4
05:49:26.011 Players.EeveePikachu54.PlayerScripts.LocalScript:5: attempt to concatenate string with nil - Client - LocalScript:5
You can see that the print statement in the Server Script ran as expected, whilst the Client Side was unable to read the referenced part, and returned as nil.
This makes spawning a part, then changing it’s duration for each player, much more complicated.
So how about sending the name of the part. This would be a bit strange, as, if you had multiple parts with the same name, the script may not be able to determine which part needs to be found.
But let’s try it anyway.
Server Script
local event = game.ReplicatedStorage.RemoteEvent
game.Players.PlayerAdded:Connect(function(player)
local partName = workspace.Proxpart.Name
local PromptSpeed = 2
event:FireAllClients(PromptSpeed, partName)
print("Server fired event to " .. player.Name .. " with speed " .. PromptSpeed .. " and part " .. partName)
end)
Client Script
local event = game.ReplicatedStorage.RemoteEvent
event.OnClientEvent:Connect(function(PromptSpeed, partName)
print("Client recieved event variable PromptSpeed: " .. PromptSpeed)
print("Client recieved event variable partName: " .. partName)
local proxpart = workspace:WaitForChild(partName)
proxpart.ProximityPrompt.HoldDuration = PromptSpeed
end)
This time, the local script succeeds in finding the part in the workspace, as shown below
05:58:42.576 Server fired event to EeveePikachu54 with speed 2 and part Proxpart - Server - Script:8
05:58:42.624 Client recieved event variable PromptSpeed: 2 - Client - LocalScript:4
05:58:42.624 Client recieved event variable partName: Proxpart - Client - LocalScript:5
After this, the proximity prompt’s duration was set from 10 to 2.
So how can we apply this in a real project, where there are multiple interactable things, with the same name, and use the same system of reducing proximity time.
Let’s move into one of my projects.
Now, the main point of focus would be in the last “segment” of the server script.
--Some Logic
if itemClone then
itemClone.Parent = spawner -- Parent the item to the spawner
itemClone.CFrame = spawner.CFrame
hasItemValue.Value = true -- Set HasItem to true
itemClone.Name =itemClone.Name .. "_Clone"
setUpProxDuration:FireAllClients(itemClone.Name)
print("setUpProxDuration event fired, cloneName variable is: "..cloneName)
-- print(string.format("Spawned a %s in Spawner: %s", itemClone.Name, spawner.Name))
end
--End of Logic
A possible solution is to rename the item, then do something like, removing “_Clone”, the last 6 characters form the name aftawards.