CustomCampfireSpawn.rbxl (162.2 KB)
![image](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/5X/9/e/4/4/9e447d2f4d7f82ebda1049d5b10e1855b1d91801.jpeg)
Ok… I made some changes…
The ‘spawns’ must be a ‘Model’ and the part that you click on, is the model’s ‘PrimaryPart’
Also, the code that places the character to its spawn location has been modified to place the character at a random position around the spawn (campfire)
--If the player's character respawns, we do this...
if SpawnListPerPlayer[player.UserId]~= nil then
task.wait()
--we get the campfire's cframe
local cf = SpawnListPerPlayer[player.UserId].PrimaryPart:GetPivot()
--we rotate the cframe by 45 degrees, multiplied by a random number between 0-7
cf = cf * CFrame.Angles(0,math.rad(math.random(0,7)*45),0)
--we create a new cframe, by stepping forward from the campfire's rotated cframe,
--then looking back from that position to the campfire
local spawnCFrame = CFrame.lookAt(cf.Position+(cf.lookVector*5),cf.Position)
--this new cframe is used to spawn the character
character:PivotTo(spawnCFrame)
end
All the other scripts have been adjusted for this…
![image](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/5X/b/6/1/7/b617dbdc1016d7fc20164b551cf0d2193ca24f11.png)
local SpawnListPerPlayer = {} --This is a list of players that have a spawn location selected
local function onPlayerAdded(player)
local function onCharacterAdded(character)
if not player:HasAppearanceLoaded() then
player.CharacterAppearanceLoaded:Wait()
end
--If the player's character respawns, we do this...
if SpawnListPerPlayer[player.UserId]~= nil then
task.wait()
--we get the campfire's cframe
local cf = SpawnListPerPlayer[player.UserId].PrimaryPart:GetPivot()
--we rotate the cframe by 45 degrees, multiplied by a random number between 0-7
cf = cf * CFrame.Angles(0,math.rad(math.random(0,7)*45),0)
--we create a new cframe, by stepping forward from the campfire's rotated cframe,
--then looking back from that position to the campfire
local spawnCFrame = CFrame.lookAt(cf.Position+(cf.lookVector*5),cf.Position)
--this new cframe is used to spawn the character
character:PivotTo(spawnCFrame)
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
local function onPlayerRemoving(player)
SpawnListPerPlayer[player.UserId] = nil
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)
local SpawnDir = workspace:WaitForChild("Spawns")
for _, s in ipairs(SpawnDir:GetChildren()) do
if s:IsA("Model") then
s.PrimaryPart:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
SpawnListPerPlayer[player.UserId] = s
end)
end
end
![image](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/5X/b/9/1/5/b915a7f37be86011133fabd200f2afed5839fb41.png)
--this script just detects when to Enable or Disable the fire effects of each campfire
--by setting the Activated custom attribute for each campfire
local campList = {} --will hold the list of campfires
for _,i in ipairs(script.Parent:GetChildren()) do --loop through all the campfires
if i:IsA("Model") then
i:SetAttribute("Activated",false) --set each campfires Activated to false (this is default)
table.insert(campList,i) --put a reference of this campfire into the list
i.PrimaryPart:WaitForChild("ClickDetector").MouseClick:Connect(function(player) --check for a mouse click on the campfire
--if the campfire was clicked...
i:SetAttribute("Activated",true) --set the campfire's Activated to true
--loop through all the campfires, and if it is NOT the one we just clicked, turn it off
for _,z in pairs(campList) do
if z~= i then
z:SetAttribute("Activated",false) --set campfire's Activated to false
end
end
end)
end
end
--this script basicallly just waits to see if the campfire's custom attribute 'Activated' changes
--if it does, this checks to see if its true or false
local campfire = script.Parent
local light = campfire:WaitForChild("Fire"):WaitForChild("PointLight")
local flame = campfire:WaitForChild("Fire"):WaitForChild("Flame")
local icon = campfire:WaitForChild("Icon")
local smoke = campfire:WaitForChild("Fire"):WaitForChild("Smoke")
campfire:GetAttributeChangedSignal("Activated"):Connect(function()
--if Activated is true, turn on the effects
if campfire:GetAttribute("Activated") == true then
light.Enabled = true
flame.Enabled = true
smoke.Enabled = true
icon.Parent = nil
else --if Activated is false, turn off the effects
light.Enabled = false
flame.Enabled = false
smoke.Enabled = false
icon.Parent = campfire
end
end)
Don’t take this the wrong way, but I feel you either need to do one of two things.
Either take some time to really get into learning how to script.
Or partner up with a scripter to help you work on your project.
Its good you ask for help in the forums as you did, but the chance of someone responding with fully written scripts and place files is very rare.
Though I love to help, its rare for me to write up a detailed example like this as my free time is pretty limited.
I tried to make it easy to understand, though so maybe you can get a better idea of what is happening in the code.
Hope this helps you out.